Sha256: 50159f7bd548083cedd3d667cb4eceb25996a607205931e159f76a8c23549504

Contents?: true

Size: 1.31 KB

Versions: 3

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true
require 'active_support/core_ext/module/attribute_accessors_per_thread'

module GoodJob
  # Thread-local attributes for passing values from Instrumentation.
  # (Cannot use ActiveSupport::CurrentAttributes because ActiveJob resets it)
  module CurrentExecution
    # @!attribute [rw] active_job_id
    #   @!scope class
    #   ActiveJob ID
    #   @return [String, nil]
    thread_mattr_accessor :active_job_id

    # @!attribute [rw] cron_key
    #   @!scope class
    #   Cron Key
    #   @return [String, nil]
    thread_mattr_accessor :cron_key

    # @!attribute [rw] error_on_discard
    #   @!scope class
    #   Error captured by discard_on
    #   @return [Exception, nil]
    thread_mattr_accessor :error_on_discard

    # @!attribute [rw] error_on_retry
    #   @!scope class
    #   Error captured by retry_on
    #   @return [Exception, nil]
    thread_mattr_accessor :error_on_retry

    # Resets attributes
    # @return [void]
    def self.reset
      self.active_job_id = nil
      self.error_on_discard = nil
      self.error_on_retry = nil
    end

    # @return [Integer] Current process ID
    def self.process_id
      Process.pid
    end

    # @return [String] Current thread name
    def self.thread_name
      (Thread.current.name || Thread.current.object_id).to_s
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
good_job-1.12.2 lib/good_job/current_execution.rb
good_job-1.12.1 lib/good_job/current_execution.rb
good_job-1.12.0 lib/good_job/current_execution.rb