1 2 ActiveRecord::ConnectionAdapters::MysqlAdapter.module_eval do 3 def execute_with_retry_once(sql, name = nil) 4 retried = false 5 begin 6 execute_without_retry_once(sql, name) 7 rescue ActiveRecord::StatementInvalid => exception 8 ActiveRecord::Base.logger.info "#{exception}, retried? #{retried}" 9 10 # Our database connection has gone away, reconnect and retry this method 11 reconnect! 12 unless retried 13 retried = true 14 retry 15 end 16 end 17 end 18 19 alias_method_chain :execute, :retry_once 20 end
You need to create an account or log in to post comments to this site.
If you were to lose connection after the update, your marking of the records would be rolled back. Executing the delete would re-establish the connect and then run the delete outside of any transaction.