Sha256: 4fca62ad9495cb4ff9bab6c8f0a7e55f868ab3f56c3159b10662213cb064f141

Contents?: true

Size: 1.15 KB

Versions: 13

Compression:

Stored size: 1.15 KB

Contents

module Appsignal
  class Hooks
    class DelayedJobPlugin < ::Delayed::Plugin
      callbacks do |lifecycle|
        lifecycle.around(:invoke_job) do |job, &block|
          invoke_with_instrumentation(job, block)
        end

        lifecycle.after(:execute) do |execute|
          Appsignal.stop
        end
      end

      def self.invoke_with_instrumentation(job, block)
        class_and_method_name = if job.payload_object.respond_to?(:appsignal_name)
                                  job.payload_object.appsignal_name
                                else
                                  job.name
                                end
        class_name, method_name = class_and_method_name.split('#')

        Appsignal.monitor_transaction(
          'perform_job.delayed_job',
          :class    => class_name,
          :method   => method_name,
          :metadata => {
            :id       => job.id.to_s,
            :queue    => job.queue,
            :priority => job.priority || 0,
            :attempts => job.attempts || 0
          },
          :queue_start => job.created_at
        ) do
          block.call(job)
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
appsignal-1.0.7 lib/appsignal/integrations/delayed_job_plugin.rb
appsignal-1.0.6 lib/appsignal/integrations/delayed_job_plugin.rb
appsignal-1.0.6.beta.4 lib/appsignal/integrations/delayed_job_plugin.rb
appsignal-1.0.6.beta.3 lib/appsignal/integrations/delayed_job_plugin.rb
appsignal-1.0.6.beta.2 lib/appsignal/integrations/delayed_job_plugin.rb
appsignal-1.0.6.beta.1 lib/appsignal/integrations/delayed_job_plugin.rb
appsignal-1.0.5 lib/appsignal/integrations/delayed_job_plugin.rb
appsignal-1.0.5.beta.4 lib/appsignal/integrations/delayed_job_plugin.rb
appsignal-1.0.5.beta.3 lib/appsignal/integrations/delayed_job_plugin.rb
appsignal-1.0.5.beta.2 lib/appsignal/integrations/delayed_job_plugin.rb
appsignal-1.0.5.beta.1 lib/appsignal/integrations/delayed_job_plugin.rb
appsignal-1.0.4 lib/appsignal/integrations/delayed_job_plugin.rb
appsignal-1.0.3 lib/appsignal/integrations/delayed_job_plugin.rb