Commit a1434ff50b7cc86e1e1a2863366e235da0f77cd7

Authored by Jakub Jirutka
1 parent 4c800342

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
... ...