Class: Axn::Async::RetryContext
- Inherits:
-
Object
- Object
- Axn::Async::RetryContext
- Defined in:
- lib/axn/async/retry_context.rb
Overview
Holds retry context information for async job execution. This context is used to determine when on_exception should be triggered and to provide retry information to exception handlers.
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#attempt ⇒ Object
readonly
Returns the value of attribute attempt.
-
#job_id ⇒ Object
readonly
Returns the value of attribute job_id.
-
#max_retries ⇒ Object
readonly
Returns the value of attribute max_retries.
Instance Method Summary collapse
- #first_attempt? ⇒ Boolean
-
#initialize(adapter:, attempt:, max_retries:, job_id: nil) ⇒ RetryContext
constructor
A new instance of RetryContext.
- #retries_exhausted? ⇒ Boolean
-
#should_trigger_on_exception?(config_mode = nil, from_exhaustion_handler: false) ⇒ Boolean
Determines if on_exception should be triggered based on config and retry state.
- #to_h ⇒ Object
Constructor Details
#initialize(adapter:, attempt:, max_retries:, job_id: nil) ⇒ RetryContext
Returns a new instance of RetryContext.
11 12 13 14 15 16 |
# File 'lib/axn/async/retry_context.rb', line 11 def initialize(adapter:, attempt:, max_retries:, job_id: nil) @adapter = adapter @attempt = attempt @max_retries = max_retries @job_id = job_id end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
9 10 11 |
# File 'lib/axn/async/retry_context.rb', line 9 def adapter @adapter end |
#attempt ⇒ Object (readonly)
Returns the value of attribute attempt.
9 10 11 |
# File 'lib/axn/async/retry_context.rb', line 9 def attempt @attempt end |
#job_id ⇒ Object (readonly)
Returns the value of attribute job_id.
9 10 11 |
# File 'lib/axn/async/retry_context.rb', line 9 def job_id @job_id end |
#max_retries ⇒ Object (readonly)
Returns the value of attribute max_retries.
9 10 11 |
# File 'lib/axn/async/retry_context.rb', line 9 def max_retries @max_retries end |
Instance Method Details
#first_attempt? ⇒ Boolean
18 19 20 |
# File 'lib/axn/async/retry_context.rb', line 18 def first_attempt? attempt == 1 end |
#retries_exhausted? ⇒ Boolean
22 23 24 |
# File 'lib/axn/async/retry_context.rb', line 22 def retries_exhausted? attempt > max_retries end |
#should_trigger_on_exception?(config_mode = nil, from_exhaustion_handler: false) ⇒ Boolean
Determines if on_exception should be triggered based on config and retry state.
For :first_and_exhausted and :only_exhausted modes, exhaustion reporting is handled by:
-
Sidekiq: Death handler (calls this with from_exhaustion_handler: true)
-
ActiveJob: after_discard callback (calls this with from_exhaustion_handler: true) Note: ActiveJob adapter requires Rails 7.1+ for these modes (raises error on older Rails)
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/axn/async/retry_context.rb', line 35 def should_trigger_on_exception?(config_mode = nil, from_exhaustion_handler: false) # Fall back to global config when no per-class override is set resolved_mode = config_mode || Axn.config.async_exception_reporting case resolved_mode when :first_and_exhausted # Regular flow reports on first attempt only. # Exhaustion handler reports only when retries were exhausted after multiple attempts, # NOT when job was discarded on first attempt (perform already reported). if from_exhaustion_handler !first_attempt? # avoid double-report when job discarded on first attempt else first_attempt? end when :only_exhausted # Only exhaustion handler should report from_exhaustion_handler else # :every_attempt and unknown modes default to triggering true end end |
#to_h ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/axn/async/retry_context.rb', line 58 def to_h { adapter:, attempt:, max_retries:, job_id:, first_attempt: first_attempt?, retries_exhausted: retries_exhausted?, }.compact end |