Module: GoodJob::CurrentThread
- Defined in:
- lib/good_job/current_thread.rb
Overview
Thread-local attributes for passing values from Instrumentation. (Cannot use ActiveSupport::CurrentAttributes because ActiveJob resets it)
Constant Summary collapse
- ACCESSORS =
Resettable accessors for thread-local values.
%i[ active_job cron_at cron_key error_on_discard error_on_retry error_on_retry_stopped job execution_interrupted retried_job retry_now ].freeze
Class Attribute Summary collapse
-
.cron_at ⇒ DateTime?
Cron At.
-
.cron_key ⇒ String?
Cron Key.
-
.error_on_discard ⇒ Exception?
Error captured by discard_on.
-
.error_on_retry ⇒ Exception?
Error captured by retry_on.
-
.error_on_retry_stopped ⇒ Exception?
Error captured by retry_stopped.
-
.execution_interrupted ⇒ Boolean?
Execution Interrupted.
-
.jobs ⇒ GoodJob::Job?
Execution.
-
.retried_job ⇒ GoodJob::Job?
Execution Retried.
-
.retry_now ⇒ Boolean?
Execution Retried.
Class Method Summary collapse
-
.active_job_id ⇒ String
UUID of the currently executing GoodJob::Job.
-
.process_id ⇒ Integer
Current process ID.
-
.reset(values = {}) ⇒ void
Resets attributes.
-
.thread_name ⇒ String
Current thread name.
-
.to_h ⇒ Hash
Exports values to hash.
-
.within {|self| ... } ⇒ void
Wrap the yielded block with CurrentThread values and reset after the block.
Class Attribute Details
.cron_at ⇒ DateTime?
Cron At
27 |
# File 'lib/good_job/current_thread.rb', line 27 thread_mattr_accessor :active_job |
.cron_key ⇒ String?
Cron Key
39 |
# File 'lib/good_job/current_thread.rb', line 39 thread_mattr_accessor :cron_key |
.error_on_discard ⇒ Exception?
Error captured by discard_on
45 |
# File 'lib/good_job/current_thread.rb', line 45 thread_mattr_accessor :error_on_discard |
.error_on_retry ⇒ Exception?
Error captured by retry_on
51 |
# File 'lib/good_job/current_thread.rb', line 51 thread_mattr_accessor :error_on_retry |
.error_on_retry_stopped ⇒ Exception?
Error captured by retry_stopped
57 |
# File 'lib/good_job/current_thread.rb', line 57 thread_mattr_accessor :error_on_retry_stopped |
.execution_interrupted ⇒ Boolean?
Execution Interrupted
69 |
# File 'lib/good_job/current_thread.rb', line 69 thread_mattr_accessor :execution_interrupted |
.jobs ⇒ GoodJob::Job?
Execution
63 |
# File 'lib/good_job/current_thread.rb', line 63 thread_mattr_accessor :job |
.retried_job ⇒ GoodJob::Job?
Execution Retried
75 |
# File 'lib/good_job/current_thread.rb', line 75 thread_mattr_accessor :retried_job |
.retry_now ⇒ Boolean?
Execution Retried
81 |
# File 'lib/good_job/current_thread.rb', line 81 thread_mattr_accessor :retry_now |
Class Method Details
.active_job_id ⇒ String
Returns UUID of the currently executing GoodJob::Job.
101 102 103 |
# File 'lib/good_job/current_thread.rb', line 101 def self.active_job_id job&.active_job_id end |
.process_id ⇒ Integer
Returns Current process ID.
106 107 108 |
# File 'lib/good_job/current_thread.rb', line 106 def self.process_id ::Process.pid end |
.reset(values = {}) ⇒ void
This method returns an undefined value.
Resets attributes
86 87 88 89 90 |
# File 'lib/good_job/current_thread.rb', line 86 def self.reset(values = {}) ACCESSORS.each do |accessor| send(:"#{accessor}=", values[accessor]) end end |
.thread_name ⇒ String
Returns Current thread name.
111 112 113 |
# File 'lib/good_job/current_thread.rb', line 111 def self.thread_name (Thread.current.name || Thread.current.object_id).to_s end |
.to_h ⇒ Hash
Exports values to hash
94 95 96 97 98 |
# File 'lib/good_job/current_thread.rb', line 94 def self.to_h ACCESSORS.index_with do |accessor| send(accessor) end end |
.within {|self| ... } ⇒ void
This method returns an undefined value.
Wrap the yielded block with CurrentThread values and reset after the block
118 119 120 121 122 123 |
# File 'lib/good_job/current_thread.rb', line 118 def self.within original_values = to_h yield(self) ensure reset(original_values) end |