Added fix for "MySQL has gone away" errors with Resque workers.
This commit is contained in:
parent
1647f46b1f
commit
3b4e7b315b
1 changed files with 17 additions and 0 deletions
17
config/initializers/connection_fix.rb
Normal file
17
config/initializers/connection_fix.rb
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
module ActiveRecord::ConnectionAdapters
|
||||||
|
class MysqlAdapter
|
||||||
|
alias_method :execute_without_retry, :execute
|
||||||
|
|
||||||
|
def execute(*args)
|
||||||
|
execute_without_retry(*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
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue