Commit dae56806df563573aa2c5e2be00be57fb12f12d7

Authored by Dmitriy Zaporozhets
2 parents c4536ae5 a1434ff5

Merge pull request #2386 from cvut/fix-passenger

Fix shared Redis connection issue on Passenger
Showing 1 changed file with 16 additions and 0 deletions   Show diff stats
config/initializers/passenger_fix.rb 0 → 100644
... ... @@ -0,0 +1,16 @@
  1 +if defined?(PhusionPassenger)
  2 +
  3 + # When you're using Passenger with smart-lv2 (default) or smart spawn method,
  4 + # Resque doesn't recognize that it has been forked and should re-establish
  5 + # Redis connection. You can see this error message in log:
  6 + # Redis::InheritedError, Tried to use a connection from a child process
  7 + # without reconnecting. You need to reconnect to Redis after forking.
  8 + #
  9 + # This solution is based on
  10 + # https://github.com/redis/redis-rb/wiki/redis-rb-on-Phusion-Passenger
  11 + #
  12 + PhusionPassenger.on_event(:starting_worker_process) do |forked|
  13 + # if we're in smart spawning mode, reconnect to Redis
  14 + Resque.redis.client.reconnect if forked
  15 + end
  16 +end
... ...