Skip to content

Instantly share code, notes, and snippets.

@clifton
Created April 28, 2011 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save clifton/946747 to your computer and use it in GitHub Desktop.
Save clifton/946747 to your computer and use it in GitHub Desktop.
class ActiveRecord::ConnectionAdapters::MysqlAdapter
def active?
true
end
def execute_with_retry_if_fail(*args)
execute_without_retry_if_fail(*args)
rescue ActiveRecord::StatementInvalid => e
if e.message =~ /server has gone away/i
warn "Server timed out, retrying"
reconnect!
retry
else
raise e
end
end
alias_method_chain :execute, :retry_if_fail
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment