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[ 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
26 |
# File 'lib/good_job/current_thread.rb', line 26 thread_mattr_accessor :cron_at |
.cron_key ⇒ String?
Cron Key
32 |
# File 'lib/good_job/current_thread.rb', line 32 thread_mattr_accessor :cron_key |
.error_on_discard ⇒ Exception?
Error captured by discard_on
38 |
# File 'lib/good_job/current_thread.rb', line 38 thread_mattr_accessor :error_on_discard |
.error_on_retry ⇒ Exception?
Error captured by retry_on
44 |
# File 'lib/good_job/current_thread.rb', line 44 thread_mattr_accessor :error_on_retry |
.error_on_retry_stopped ⇒ Exception?
Error captured by retry_stopped
50 |
# File 'lib/good_job/current_thread.rb', line 50 thread_mattr_accessor :error_on_retry_stopped |
.execution_interrupted ⇒ Boolean?
Execution Interrupted
62 |
# File 'lib/good_job/current_thread.rb', line 62 thread_mattr_accessor :execution_interrupted |
.jobs ⇒ GoodJob::Job?
Execution
56 |
# File 'lib/good_job/current_thread.rb', line 56 thread_mattr_accessor :job |
.retried_job ⇒ GoodJob::Job?
Execution Retried
68 |
# File 'lib/good_job/current_thread.rb', line 68 thread_mattr_accessor :retried_job |
.retry_now ⇒ Boolean?
Execution Retried
74 |
# File 'lib/good_job/current_thread.rb', line 74 thread_mattr_accessor :retry_now |
Class Method Details
.active_job_id ⇒ String
Returns UUID of the currently executing GoodJob::Job.
94 95 96 |
# File 'lib/good_job/current_thread.rb', line 94 def self.active_job_id job&.active_job_id end |
.process_id ⇒ Integer
Returns Current process ID.
99 100 101 |
# File 'lib/good_job/current_thread.rb', line 99 def self.process_id ::Process.pid end |
.reset(values = {}) ⇒ void
This method returns an undefined value.
Resets attributes
79 80 81 82 83 |
# File 'lib/good_job/current_thread.rb', line 79 def self.reset(values = {}) ACCESSORS.each do |accessor| send(:"#{accessor}=", values[accessor]) end end |
.thread_name ⇒ String
Returns Current thread name.
104 105 106 |
# File 'lib/good_job/current_thread.rb', line 104 def self.thread_name (Thread.current.name || Thread.current.object_id).to_s end |
.to_h ⇒ Hash
Exports values to hash
87 88 89 90 91 |
# File 'lib/good_job/current_thread.rb', line 87 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
111 112 113 114 115 116 |
# File 'lib/good_job/current_thread.rb', line 111 def self.within original_values = to_h yield(self) ensure reset(original_values) end |