From db190c0880d7d6b9a1e1ac4717ed2ca648c21589 Mon Sep 17 00:00:00 2001 From: Mick Staugaard Date: Mon, 5 Apr 2010 17:35:26 -0700 Subject: [PATCH] Resque instrumentation now uses the resque-multi-job-forks plugin when available --- CHANGELOG | 4 +++ lib/rpm_contrib/instrumentation/resque.rb | 38 ++++++++++------------- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index f551a42..88a586d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,7 @@ +* Version 1.0.7 + + Resque instrumentation now supports the resque-multi-job-forks plugin + * Version 1.0.6 Update newrelic dependency: depends on 2.11.1 diff --git a/lib/rpm_contrib/instrumentation/resque.rb b/lib/rpm_contrib/instrumentation/resque.rb index cc2e9e0..4ca6189 100644 --- a/lib/rpm_contrib/instrumentation/resque.rb +++ b/lib/rpm_contrib/instrumentation/resque.rb @@ -7,34 +7,28 @@ module RPMContrib module Instrumentation module ResqueInstrumentation - - ::Resque::Worker.class_eval do + ::Resque::Job.class_eval do include NewRelic::Agent::Instrumentation::ControllerInstrumentation - old_process_method = instance_method(:process) - define_method(:process) do | *args | - if args[0] - class_name = args[0].payload_class.name - else - class_name = 'Resque::Job' - end - name = 'process' + + old_perform_method = instance_method(:perform) + + define_method(:perform) do + class_name = (payload_class ||self.class).name NewRelic::Agent.reset_stats if NewRelic::Agent.respond_to? :reset_stats - perform_action_with_newrelic_trace(:name => name, :class_name => class_name, + perform_action_with_newrelic_trace(:name => 'perform', :class_name => class_name, :category => 'OtherTransaction/ResqueJob') do - old_process_method.bind(self).call(*args) + old_perform_method.bind(self).call end - NewRelic::Agent.shutdown + + NewRelic::Agent.shutdown unless defined?(::Resque.before_child_exit) end - - old_work_method = instance_method(:work) - - define_method(:work) do | *args | - RAILS_DEFAULT_LOGGER.info "Sarting Resque monitoring" - old_work_method.bind(self).call(*args) + end + + if defined?(::Resque.before_child_exit) + ::Resque.before_child_exit do |worker| + NewRelic::Agent.shutdown end end - end end -end if defined?(::Resque::Worker) and not NewRelic::Control.instance['disable_resque'] - +end if defined?(::Resque::Job) and not NewRelic::Control.instance['disable_resque']