Class: Appsignal::Hooks::DelayedJobPlugin Private

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

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Class Method Summary collapse

Methods included from Helpers

extract_value, string_or_inspect, truncate

Class Method Details

.invoke_with_instrumentation(job, block) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



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
46
47
48
49
50
51
# File 'lib/appsignal/integrations/delayed_job_plugin.rb', line 17

def self.invoke_with_instrumentation(job, block)
  payload = job.payload_object

  if payload.respond_to? :job_data
    # ActiveJob
    job_data = payload.job_data
    args = job_data.fetch("arguments", {})
    class_name = job_data["job_class"]
    method_name = "perform"
  else
    # Delayed Job
    args = extract_value(job.payload_object, :args, {})
    class_and_method_name = extract_value(job.payload_object, :appsignal_name, job.name)
    class_name, method_name = class_and_method_name.split("#")
  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, :id, nil, true),
      :queue    => extract_value(job, :queue),
      :priority => extract_value(job, :priority, 0),
      :attempts => extract_value(job, :attempts, 0)
    },
    :params      => params,
    :queue_start => extract_value(job, :run_at)
  ) do
    block.call(job)
  end
end