-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ff64d3e
commit efc5cbc
Showing
3 changed files
with
51 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,49 @@ | ||
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| | ||
# 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 | ||
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