How do I go about retrying entire ActiveRecord transactions in rails in event of a mysql connection failure for a few seconds?
So far I have gone about retrying just the last query that failed by overriding the execute method of ActiveRecord::ConnectionAdapters::Mysql2Adapter
class ActiveRecord::ConnectionAdapters::Mysql2Adapter
def execute(*args)
begin
super(*args)
rescue ActiveRecord::StatementInvalid => e
retry
end
end
end
This is however leads to inconsistent transactions due to which I decided its better if I retry the entire transaction instead of just the last query.
Is there anyway I can get the details of the current transaction and just retry it from the beginning?