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
task "resque:pool:setup" do
# Close any sockets or files in pool master
# 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
# Load NewRelic here. We've already forked and we're good to go.
: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
Resque.before_fork do |job|
Resque.after_fork do |job|
NewRelic::Agent.after_fork(:report_to_channel => job.object_id)

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


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