Module: ScoutApm::Instruments::DelayedJobInstruments

Defined in:
lib/scout_apm/instruments/delayed_job.rb

Instance Method Summary collapse

Instance Method Details

#method_from_handler(handler) ⇒ Object



49
50
51
52
53
54
# File 'lib/scout_apm/instruments/delayed_job.rb', line 49

def method_from_handler(handler)
  job_handler = YAML.load(handler)
  klass = job_handler.object.name
  method = job_handler.method_name
  "#{klass}##{method}"
end

#run_with_scout_instruments(job) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/scout_apm/instruments/delayed_job.rb', line 29

def run_with_scout_instruments(job)
  scout_method_name = method_from_handler(job.handler)
  queue = job.queue
  latency = (Time.now.to_f - job.created_at.to_f) * 1000

  ScoutApm::Agent.instance.store.track_one!("Queue", queue, 0, {:extra_metrics => {:latency => latency}})
  req = ScoutApm::RequestManager.lookup
  req.job!
  req.start_layer( ScoutApm::Layer.new("Job", scout_method_name) )

  begin
    run_without_scout_instruments(job)
  rescue
    req.error!
    raise
  ensure
    req.stop_layer
  end
end