Commit 994fe9fd31f20ea9122fd8819d23f621cfae7989

Authored by Sytse Sijbrandij
1 parent fe059b6c

Fix for Resque forking might cause stuck workers for the threaded Sidekiq.

Showing 1 changed file with 0 additions and 36 deletions   Show diff stats
config/initializers/connection_fix.rb
... ... @@ -1,36 +0,0 @@
1   -# from http://gist.github.com/238999
2   -#
3   -# If your workers are inactive for a long period of time, they'll lose
4   -# their MySQL connection.
5   -#
6   -# This hack ensures we re-connect whenever a connection is
7   -# lost. Because, really. why not?
8   -#
9   -# Stick this in RAILS_ROOT/config/initializers/connection_fix.rb (or somewhere similar)
10   -#
11   -# From:
12   -# http://coderrr.wordpress.com/2009/01/08/activerecord-threading-issues-and-resolutions/
13   -
14   -if defined?(ActiveRecord::ConnectionAdapters::Mysql2Adapter)
15   -
16   - module ActiveRecord::ConnectionAdapters
17   -
18   - class Mysql2Adapter
19   - alias_method :execute_without_retry, :execute
20   -
21   - def execute(*args)
22   - execute_without_retry(*args)
23   - rescue ActiveRecord::StatementInvalid => e
24   - if e.message =~ /server has gone away/i
25   - warn "Server timed out, retrying"
26   - reconnect!
27   - retry
28   - else
29   - raise e
30   - end
31   - end
32   - end
33   -
34   - end
35   -
36   -end