Class: Appsignal::Hooks::DelayedJobPlugin

Inherits:
Delayed::Plugin
  • Object
show all
Extended by:
Helpers
Defined in:
lib/appsignal/integrations/delayed_job_plugin.rb

Class Method Summary collapse

Methods included from Helpers

extract_value, format_args, string_or_inspect, truncate

Class Method Details

.invoke_with_instrumentation(job, block) ⇒ Object


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/appsignal/integrations/delayed_job_plugin.rb', line 16

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
  end

  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      => format_args(args),
    :queue_start => extract_value(job_data, :created_at)
  ) do
    block.call(job)
  end
end