Sha256: beceb42c440ff92b8972bb24717f4a74b725d850ac186e44cb2d75fb5f1b2e27

Contents?: true

Size: 1.74 KB

Versions: 7

Compression:

Stored size: 1.74 KB

Contents

module Appsignal
  class Hooks
    # @api private
    class DelayedJobPlugin < ::Delayed::Plugin
      extend Appsignal::Hooks::Helpers

      callbacks do |lifecycle|
        lifecycle.around(:invoke_job) do |job, &block|
          invoke_with_instrumentation(job, block)
        end

        lifecycle.after(:execute) do |_execute|
          Appsignal.stop("delayed job")
        end
      end

      def self.invoke_with_instrumentation(job, block)
        if job.respond_to?(:payload_object)
          # Direct Delayed Job
          class_and_method_name = extract_value(job.payload_object, :appsignal_name, job.name)
          class_name, method_name = class_and_method_name.split("#")
          args = extract_value(job.payload_object, :args, {})
          job_data = job
        elsif job.respond_to?(:job_data)
          # Via ActiveJob
          class_name, method_name = job.job_data[:name].split("#")
          args = job.job_data[:args] || {}
          job_data = job.job_data
        else
          args = {}
        end
        params = Appsignal::Utils::ParamsSanitizer.sanitize args,
          :filter_parameters => Appsignal.config[:filter_parameters]

        Appsignal.monitor_transaction(
          "perform_job.delayed_job",
          :class    => class_name,
          :method   => method_name,
          :metadata => {
            :id       => extract_value(job_data, :id, nil, true),
            :queue    => extract_value(job_data, :queue),
            :priority => extract_value(job_data, :priority, 0),
            :attempts => extract_value(job_data, :attempts, 0)
          },
          :params      => params,
          :queue_start => extract_value(job_data, :run_at)
        ) do
          block.call(job)
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
appsignal-2.3.3 lib/appsignal/integrations/delayed_job_plugin.rb
appsignal-2.3.3.beta.1 lib/appsignal/integrations/delayed_job_plugin.rb
appsignal-2.3.2 lib/appsignal/integrations/delayed_job_plugin.rb
appsignal-2.3.1 lib/appsignal/integrations/delayed_job_plugin.rb
appsignal-2.3.0 lib/appsignal/integrations/delayed_job_plugin.rb
appsignal-2.3.0.beta.3 lib/appsignal/integrations/delayed_job_plugin.rb
appsignal-2.3.0.beta.2 lib/appsignal/integrations/delayed_job_plugin.rb