module Resque
  module Plugins
    module NewRelicInstrumentation
      include NewRelic::Agent::Instrumentation::ControllerInstrumentation

      def around_perform_with_monitoring(*args)
        perform_action_with_newrelic_trace(:name => 'perform', :class_name => class_name, :category => 'OtherTransaction/ResqueJob') do
          yield(*args)
        end
      end
    end
  end
end

module RPMContrib
  module Instrumentation
    module Resque
      ::Resque.before_first_fork do
        NewRelic::Agent.manual_start(:dispatcher => :resque)
      end

      ::Resque.after_fork do
        NewRelic::Agent.after_fork(:force_reconnect => false)
      end

      ::Resque::Job.class_eval do
        include ::Resque::Plugins::NewRelicInstrumentation
      end
    end
  end
end if defined?(::Resque) and not NewRelic::Control.instance['disable_resque']


module Resque
  module Plugins
    module NewRelicInstrumentation
      include NewRelic::Agent::Instrumentation::ControllerInstrumentation

      def around_perform_with_monitoring(*args)
        perform_action_with_newrelic_trace(:name => 'perform', :class_name => class_name, :category => 'OtherTransaction/ResqueJob') do
          yield(*args)
        end

        NewRelic::Agent.shutdown
      end
    end
  end
end

module RPMContrib
  module Instrumentation
    module Resque
      ::Resque.before_first_fork do
        NewRelic::Agent.manual_start(:dispatcher => :resque)
      end

      ::Resque.after_fork do
        NewRelic::Agent.after_fork(:force_reconnect => false)
      end

      ::Resque::Job.class_eval do
        include ::Resque::Plugins::NewRelicInstrumentation
      end
    end
  end
end if defined?(::Resque) and not NewRelic::Control.instance['disable_resque']


Add a shutdown method to Resque instrumentation to ensure data is saved
Add a shutdown method to Resque instrumentation to ensure data is saved

Signed-off-by: Justin George <26962c8b46ccf1e15704afec3ad512e5c5878696@gmail.com>
