Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Working resque pool setup for NewRelic

View resque_pool.rake
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
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!
# This happens after resque-pool has forked your worker
# but before it performs Resque::Worker#startup
Resque::Pool.after_prefork do |job|
 
# Re-connect to your database
ActiveRecord::Base.establish_connection
# Load NewRelic here. We've already forked and we're good to go.
NewRelic::Agent.manual_start(
:dispatcher => :resque,
:sync_startup => true,
:start_channel_listener => true
)
Resque.before_first_fork do
# Normally you'd do this here if you aren't using resque-pool
# NewRelic::Agent.manual_start(
# :dispatcher => :resque,
# :sync_startup => true,
# :start_channel_listener => true
# )
# Empty block so that you nuke newrelic_rpm's built in hooks
# You can do other things here though or just set this to nil
end
Resque.before_fork do |job|
NewRelic::Agent.register_report_channel(job.object_id)
end
Resque.after_fork do |job|
NewRelic::Agent.after_fork(:report_to_channel => job.object_id)
end
end
end

Does it really work? I've been trying without success...

jure commented

This actually did not work for us, until we set the NEWRELIC_DISPATCHER env variable in our Rakefile, before it just wasn't detecting the resque dispatcher.

Just to further clarify, the NEWRELIC_DISPATCHER env variable (as referenced in the comment above) should be set to "resque", since New Relic normally sets that variable on agent start-up to whatever dispatcher it detects.

FYI, we've just released version 3.6.7 of the newrelic_rpm gem, which should support resque-pool out of the box!

Works great for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.