Created
January 21, 2010 20:38
-
-
Save graysky/283171 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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