Class: Fractor::Workflow::RetryState
- Inherits:
-
Object
- Object
- Fractor::Workflow::RetryState
- Defined in:
- lib/fractor/workflow/retry_config.rb
Overview
Tracks retry state for a job execution
Instance Attribute Summary collapse
-
#attempt ⇒ Object
readonly
Returns the value of attribute attempt.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#job_name ⇒ Object
readonly
Returns the value of attribute job_name.
-
#started_at ⇒ Object
readonly
Returns the value of attribute started_at.
Instance Method Summary collapse
-
#exhausted?(max_attempts) ⇒ Boolean
Check if retry attempts have been exhausted.
-
#initialize(job_name) ⇒ RetryState
constructor
A new instance of RetryState.
-
#last_error ⇒ Exception?
Get the last error that occurred.
-
#record_failure(error) ⇒ Object
Record a failed attempt.
-
#summary ⇒ Hash
Get a summary of all retry attempts.
-
#total_time ⇒ Numeric
Get total execution time across all attempts.
Constructor Details
#initialize(job_name) ⇒ RetryState
Returns a new instance of RetryState.
100 101 102 103 104 105 |
# File 'lib/fractor/workflow/retry_config.rb', line 100 def initialize(job_name) @job_name = job_name @attempt = 1 @errors = [] @started_at = Time.now end |
Instance Attribute Details
#attempt ⇒ Object (readonly)
Returns the value of attribute attempt.
98 99 100 |
# File 'lib/fractor/workflow/retry_config.rb', line 98 def attempt @attempt end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
98 99 100 |
# File 'lib/fractor/workflow/retry_config.rb', line 98 def errors @errors end |
#job_name ⇒ Object (readonly)
Returns the value of attribute job_name.
98 99 100 |
# File 'lib/fractor/workflow/retry_config.rb', line 98 def job_name @job_name end |
#started_at ⇒ Object (readonly)
Returns the value of attribute started_at.
98 99 100 |
# File 'lib/fractor/workflow/retry_config.rb', line 98 def started_at @started_at end |
Instance Method Details
#exhausted?(max_attempts) ⇒ Boolean
Check if retry attempts have been exhausted
121 122 123 |
# File 'lib/fractor/workflow/retry_config.rb', line 121 def exhausted?(max_attempts) @attempt > max_attempts end |
#last_error ⇒ Exception?
Get the last error that occurred
127 128 129 |
# File 'lib/fractor/workflow/retry_config.rb', line 127 def last_error @errors.last&.dig(:error) end |
#record_failure(error) ⇒ Object
Record a failed attempt
109 110 111 112 113 114 115 116 |
# File 'lib/fractor/workflow/retry_config.rb', line 109 def record_failure(error) @errors << { attempt: @attempt, error: error, timestamp: Time.now, } @attempt += 1 end |
#summary ⇒ Hash
Get a summary of all retry attempts
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/fractor/workflow/retry_config.rb', line 139 def summary { job_name: @job_name, total_attempts: @attempt - 1, total_time: total_time, errors: @errors.map do |err| { attempt: err[:attempt], error_class: err[:error].class.name, error_message: err[:error]., timestamp: err[:timestamp], } end, } end |
#total_time ⇒ Numeric
Get total execution time across all attempts
133 134 135 |
# File 'lib/fractor/workflow/retry_config.rb', line 133 def total_time Time.now - @started_at end |