Sha256: 24c4ab2218891fd4d797595270d038cc73977d4fc4786727b049f718e8a8618f

Contents?: true

Size: 1.01 KB

Versions: 34

Compression:

Stored size: 1.01 KB

Contents

# 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)
      end

      around_perform do |_, block|
        instrument :perform_start
        instrument :perform, &block
      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
  end
end

Version data entries

34 entries across 34 versions & 4 rubygems

Version Path
activejob-6.1.7.10 lib/active_job/instrumentation.rb
activejob-6.1.7.9 lib/active_job/instrumentation.rb
activejob-6.1.7.8 lib/active_job/instrumentation.rb
activejob-6.1.7.7 lib/active_job/instrumentation.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activejob-6.1.6.1/lib/active_job/instrumentation.rb
activejob-6.1.7.6 lib/active_job/instrumentation.rb
activejob-6.1.7.5 lib/active_job/instrumentation.rb
activejob-6.1.7.4 lib/active_job/instrumentation.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/activejob-6.1.6.1/lib/active_job/instrumentation.rb
activejob-6.1.7.3 lib/active_job/instrumentation.rb
activejob-6.1.7.2 lib/active_job/instrumentation.rb
activejob-6.1.7.1 lib/active_job/instrumentation.rb
activejob-6.1.7 lib/active_job/instrumentation.rb
activejob-6.1.6.1 lib/active_job/instrumentation.rb
activejob-6.1.6 lib/active_job/instrumentation.rb
activejob-6.1.5.1 lib/active_job/instrumentation.rb
activejob-6.1.5 lib/active_job/instrumentation.rb
activejob-6.1.4.7 lib/active_job/instrumentation.rb
activejob-6.1.4.6 lib/active_job/instrumentation.rb
activejob-6.1.4.5 lib/active_job/instrumentation.rb