Skip to content

Instantly share code, notes, and snippets.

@graysky
Created January 21, 2010 20:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save graysky/283171 to your computer and use it in GitHub Desktop.
Save graysky/283171 to your computer and use it in GitHub Desktop.
# Put in environment.rb to force Vanity to make a new connection to Redis
# to play nice with Passenger's smart forking.
# monkey patch vanity to force new redis connection when Passenger forks
if defined?(PhusionPassenger)
class Vanity::Playground
def reconnect_redis
@redis = nil
# Need to remove method or unable to force a reconnect because it
# hits the method, not the variable.
class << self ; self ; end.send(:remove_method, :redis)
redis # Make a new connectiont to redis
end
end
PhusionPassenger.on_event(:starting_worker_process) do |forked|
if forked
# We’re in smart spawning mode.
begin
Vanity.playground.reconnect_redis
rescue Exception => e
RAILS_DEFAULT_LOGGER.error "Error connecting to redis: #{e.to_s}"
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment