2019-09-23 12:29:52 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module ActiveJob
|
|
|
|
module Instrumentation #:nodoc:
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
included do
|
2019-09-23 16:13:54 -04:00
|
|
|
around_enqueue do |_, block|
|
|
|
|
scheduled_at ? instrument(:enqueue_at, &block) : instrument(:enqueue, &block)
|
2019-09-23 12:29:52 -04:00
|
|
|
end
|
|
|
|
|
2019-09-23 16:13:54 -04:00
|
|
|
around_perform do |_, block|
|
|
|
|
instrument :perform_start
|
|
|
|
instrument :perform, &block
|
2019-09-23 12:29:52 -04:00
|
|
|
end
|
|
|
|
end
|
2019-09-23 16:13:54 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
def instrument(operation, payload = {}, &block)
|
|
|
|
ActiveSupport::Notifications.instrument \
|
2019-09-23 16:53:05 -04:00
|
|
|
"#{operation}.active_job", payload.merge(adapter: queue_adapter, job: self), &block
|
2019-09-23 16:13:54 -04:00
|
|
|
end
|
2019-09-23 12:29:52 -04:00
|
|
|
end
|
|
|
|
end
|