Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# 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
You can’t perform that action at this time.