Module: RorVsWild::Plugin::DelayedJob

Defined in:
lib/rorvswild/plugin/delayed_job.rb

Class Method Summary collapse

Class Method Details

.setup(agent) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rorvswild/plugin/delayed_job.rb', line 8

def self.setup(agent)
  return if @installed
  return unless defined?(Delayed::Plugin)
  Delayed::Worker.plugins << Class.new(Delayed::Plugin) do
    callbacks do |lifecycle|
      lifecycle.around(:invoke_job) do |job, *args, &block|
        if job.payload_object.class.name == "ActiveJob::QueueAdapters::DelayedJobAdapter::JobWrapper"
          job_name, job_args = job.payload_object.job_data.values_at("job_class", "arguments")
        elsif job.payload_object.is_a?(Delayed::PerformableMethod)
          job_name, job_args = job.name, job.payload_object.args
        else
          job_name, job_args = job.name, job.payload_object
        end
        RorVsWild.agent.measure_job(job_name, parameters: job_args) { block.call(job) }
      end
    end
  end
  @installed = true
end