Class: ScoutApm::BackgroundJobIntegrations::GoodJob

Inherits:
Object
  • Object
show all
Defined in:
lib/scout_apm/background_job_integrations/good_job.rb

Constant Summary collapse

UNKNOWN_QUEUE_PLACEHOLDER =
'default'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



5
6
7
# File 'lib/scout_apm/background_job_integrations/good_job.rb', line 5

def logger
  @logger
end

Instance Method Details

#forking?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/scout_apm/background_job_integrations/good_job.rb', line 15

def forking?
  false
end

#installObject



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
# File 'lib/scout_apm/background_job_integrations/good_job.rb', line 19

def install
  ActiveSupport.on_load(:active_job) do
    include ScoutApm::Tracer

    around_perform do |job, block|
      # I have a sneaking suspicion there is a better way to handle Agent starting
      # Maybe hook into GoodJob lifecycle events?
      req = ScoutApm::RequestManager.lookup
      latency = Time.now - (job.scheduled_at || job.enqueued_at) rescue 0
      req.annotate_request(queue_latency: latency)

      begin
        req.start_layer ScoutApm::Layer.new("Queue", job.queue_name.presence || UNKNOWN_QUEUE_PLACEHOLDER)
        started_queue = true # Following Convention
        req.start_layer ScoutApm::Layer.new("Job", job.class.name)
        started_job = true # Following Convention

        block.call
      rescue
        req.error!
        raise
      ensure
        req.stop_layer if started_job
        req.stop_layer if started_queue
      end
    end
  end
end

#nameObject



7
8
9
# File 'lib/scout_apm/background_job_integrations/good_job.rb', line 7

def name
  :good_job
end

#present?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/scout_apm/background_job_integrations/good_job.rb', line 11

def present?
  defined?(::GoodJob::VERSION)
end