-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Based entirely on existing Good Job work.
- Loading branch information
Showing
3 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
module ScoutApm | ||
module BackgroundJobIntegrations | ||
class SolidQueue | ||
UNKNOWN_QUEUE_PLACEHOLDER = 'default'.freeze | ||
attr_reader :logger | ||
|
||
def name | ||
:solid_queue | ||
end | ||
|
||
def present? | ||
defined?(::SolidQueue::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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters