Skip to content

Commit

Permalink
Respect Differences in ActiveJob/GoodJob API
Browse files Browse the repository at this point in the history
  • Loading branch information
benngarcia committed Aug 6, 2024
1 parent 3036d5b commit 47e5eaf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/scout_apm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ module ScoutApm
require 'scout_apm/background_job_integrations/sneakers'
require 'scout_apm/background_job_integrations/que'
require 'scout_apm/background_job_integrations/legacy_sneakers'
require 'scout_apm/background_job_integrations/good_job'

require 'scout_apm/framework_integrations/rails_2'
require 'scout_apm/framework_integrations/rails_3_or_4'
Expand Down
7 changes: 4 additions & 3 deletions lib/scout_apm/background_job_integrations/good_job.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module ScoutApm
module BackgroundJobIntegrations
class GoodJob
UNKNOWN_QUEUE_PLACEHOLDER = 'default'.freeze
attr_reader :logger

def initialize(logger)
Expand Down Expand Up @@ -29,13 +30,13 @@ def install
# Maybe hook into GoodJob lifecycle events?
ScoutApm::Agent.instance.start_background_worker unless ScoutApm::Agent.instance.background_worker_running?
req = ScoutApm::RequestManager.lookup
latency = Time.now - job.scheduled_at rescue 0
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)
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.job_class)
req.start_layer ScoutApm::Layer.new("Job", job.class.name)
started_job = true # Following Convention

block.call
Expand Down

0 comments on commit 47e5eaf

Please sign in to comment.