1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activejob/lib/active_job/instrumentation.rb

41 lines
1.1 KiB
Ruby
Raw Normal View History

2019-09-23 12:29:52 -04:00
# frozen_string_literal: true
module ActiveJob
module Instrumentation #:nodoc:
extend ActiveSupport::Concern
included do
around_enqueue do |_, block|
scheduled_at ? instrument(:enqueue_at, &block) : instrument(:enqueue, &block)
2019-09-23 12:29:52 -04:00
end
around_perform do |_, block|
ActiveSupport::Notifications.instrument \
"perform_start.active_job", { adapter: queue_adapter, job: self }, &block
2019-09-23 12:29:52 -04:00
end
end
private
def instrument(operation, payload = {}, &block)
enhanced_block = ->(event_payload) do
value = block.call if block
if defined?(@_halted_callback_hook_called) && @_halted_callback_hook_called
event_payload[:aborted] = true
@_halted_callback_hook_called = nil
end
value
end
ActiveSupport::Notifications.instrument \
"#{operation}.active_job", payload.merge(adapter: queue_adapter, job: self), &enhanced_block
end
def halted_callback_hook(*)
super
@_halted_callback_hook_called = true
end
2019-09-23 12:29:52 -04:00
end
end