Sha256: 806e61704b35a6bf7db812eaacef3a11953ec06929135440a2feb52831919cc0

Contents?: true

Size: 1.45 KB

Versions: 13

Compression:

Stored size: 1.45 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] 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

    # @!attribute [rw] good_job
    #   @!scope class
    #   Cron Key
    #   @return [GoodJob::Job, nil]
    thread_mattr_accessor :good_job

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

    # @return [String] UUID of the currently executing GoodJob::Job
    def self.active_job_id
      good_job&.active_job_id
    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

13 entries across 13 versions & 1 rubygems

Version Path
good_job-1.99.2 lib/good_job/current_execution.rb
good_job-2.1.0 lib/good_job/current_execution.rb
good_job-2.0.5 lib/good_job/current_execution.rb
good_job-2.0.4 lib/good_job/current_execution.rb
good_job-2.0.3 lib/good_job/current_execution.rb
good_job-2.0.2 lib/good_job/current_execution.rb
good_job-1.99.1 lib/good_job/current_execution.rb
good_job-2.0.1 lib/good_job/current_execution.rb
good_job-2.0.0 lib/good_job/current_execution.rb
good_job-1.99.0 lib/good_job/current_execution.rb
good_job-1.13.2 lib/good_job/current_execution.rb
good_job-1.13.1 lib/good_job/current_execution.rb
good_job-1.13.0 lib/good_job/current_execution.rb