Sha256: 267177d90d83e188bf9833d88801c1f2d1533cf9b2fa9d4f558f1f57a03246c3

Contents?: true

Size: 1.05 KB

Versions: 37

Compression:

Stored size: 1.05 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
    end

    def perform_now
      instrument(:perform) { super }
    end

    private
      def _perform_job
        instrument(:perform_start)
        super
      end

      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

37 entries across 35 versions & 4 rubygems

Version Path
activejob-7.0.8.6 lib/active_job/instrumentation.rb
activejob-7.0.8.5 lib/active_job/instrumentation.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/activejob-7.0.8.4/lib/active_job/instrumentation.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/activejob-7.0.5.1/lib/active_job/instrumentation.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/activejob-7.0.5.1/lib/active_job/instrumentation.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/activejob-7.0.5.1/lib/active_job/instrumentation.rb
activejob-7.0.8.4 lib/active_job/instrumentation.rb
activejob-7.0.8.1 lib/active_job/instrumentation.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activejob-7.0.3.1/lib/active_job/instrumentation.rb
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/activejob-7.0.2.3/lib/active_job/instrumentation.rb
activejob-7.0.8 lib/active_job/instrumentation.rb
activejob-7.0.7.2 lib/active_job/instrumentation.rb
activejob-7.0.7.1 lib/active_job/instrumentation.rb
activejob-7.0.7 lib/active_job/instrumentation.rb
activejob-7.0.6 lib/active_job/instrumentation.rb
activejob-7.0.5.1 lib/active_job/instrumentation.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/activejob-7.0.3.1/lib/active_job/instrumentation.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/activejob-7.0.2.3/lib/active_job/instrumentation.rb
activejob-7.0.5 lib/active_job/instrumentation.rb
activejob-7.0.4.3 lib/active_job/instrumentation.rb