Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Working resque pool setup for NewRelic
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
@tanob
tanob commented Jan 11, 2013

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

@jure
jure commented Apr 15, 2013

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.

@lauradiane

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.

@benweint
benweint commented Sep 9, 2013

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

@gregtaylor99

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.