public
Created

Resque Pool and NewRelic

  • Download Gist
resque_pool.rake
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
require 'resque/pool/tasks'
 
# this task will get called before resque:pool:setup
# preload the rails environment in the pool master
task "resque:setup" => :environment do
# generic worker setup, e.g. Hoptoad for failed jobs
end
 
task "resque:pool:setup" do
# close any sockets or files in pool master
ActiveRecord::Base.connection.disconnect!
# and re-open them in the resque worker parent
Resque::Pool.after_prefork do |job|
NewRelic::Agent.after_fork(:force_reconnect => true)
ActiveRecord::Base.establish_connection
end
end

After running this in production for a while, I have to say: Don't do this. For some reason, jobs just silently fail and die.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.