Skip to content

Commit

Permalink
Add solid queue
Browse files Browse the repository at this point in the history
  • Loading branch information
lancetarn committed Aug 15, 2024
1 parent a0048db commit 2c10d47
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions solid_queue.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
module ScoutApm
module BackgroundJobIntegrations
class GoodJob
UNKNOWN_QUEUE_PLACEHOLDER = 'default'.freeze
attr_reader :logger

def name
:good_job
end

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

def forking?
false
end

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

around_perform do |job, block|
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
end
end
end

0 comments on commit 2c10d47

Please sign in to comment.