Skip to content

Instantly share code, notes, and snippets.

@yvmarques
Created March 27, 2012 13:49
Show Gist options
  • Save yvmarques/2216040 to your computer and use it in GitHub Desktop.
Save yvmarques/2216040 to your computer and use it in GitHub Desktop.
module ActiveRecord::ConnectionAdapters
class Mysql2Adapter
alias_method :execute_without_retry, :execute
def execute(*args)
execute_without_retry(*args)
rescue Mysql2::Error => e
if e.message =~ /server has gone away/i
warn "Server timed out, retrying"
reconnect!
retry
else
raise e
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment