Class: Fractor::Workflow::RetryConfig
- Inherits:
-
Object
- Object
- Fractor::Workflow::RetryConfig
- Defined in:
- lib/fractor/workflow/retry_config.rb
Overview
Configuration for job retry behavior
Instance Attribute Summary collapse
-
#retryable_errors ⇒ Object
readonly
Returns the value of attribute retryable_errors.
-
#strategy ⇒ Object
readonly
Returns the value of attribute strategy.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
Class Method Summary collapse
-
.create_strategy(**options) ⇒ RetryStrategy
Create a retry strategy from options.
-
.from_options(**options) ⇒ RetryConfig
Create a retry config from a hash of options.
Instance Method Summary collapse
-
#delay_for(attempt) ⇒ Numeric
Calculate delay for a given attempt.
-
#initialize(strategy: NoRetry.new, timeout: nil, retryable_errors: [StandardError]) ⇒ RetryConfig
constructor
A new instance of RetryConfig.
-
#max_attempts ⇒ Integer
Get maximum number of retry attempts.
-
#retryable?(error) ⇒ Boolean
Check if an error should trigger a retry.
Constructor Details
#initialize(strategy: NoRetry.new, timeout: nil, retryable_errors: [StandardError]) ⇒ RetryConfig
Returns a new instance of RetryConfig.
11 12 13 14 15 16 17 18 19 |
# File 'lib/fractor/workflow/retry_config.rb', line 11 def initialize( strategy: NoRetry.new, timeout: nil, retryable_errors: [StandardError] ) @strategy = strategy @timeout = timeout @retryable_errors = Array(retryable_errors) end |
Instance Attribute Details
#retryable_errors ⇒ Object (readonly)
Returns the value of attribute retryable_errors.
9 10 11 |
# File 'lib/fractor/workflow/retry_config.rb', line 9 def retryable_errors @retryable_errors end |
#strategy ⇒ Object (readonly)
Returns the value of attribute strategy.
9 10 11 |
# File 'lib/fractor/workflow/retry_config.rb', line 9 def strategy @strategy end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
9 10 11 |
# File 'lib/fractor/workflow/retry_config.rb', line 9 def timeout @timeout end |
Class Method Details
.create_strategy(**options) ⇒ RetryStrategy
Create a retry strategy from options
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/fractor/workflow/retry_config.rb', line 62 def self.create_strategy(**) backoff = [:backoff] || :exponential max_attempts = [:max_attempts] || 3 max_delay = [:max_delay] case backoff when :exponential ExponentialBackoff.new( initial_delay: [:initial_delay] || 1, multiplier: [:multiplier] || 2, max_attempts: max_attempts, max_delay: max_delay, ) when :linear LinearBackoff.new( initial_delay: [:initial_delay] || 1, increment: [:increment] || 1, max_attempts: max_attempts, max_delay: max_delay, ) when :constant ConstantDelay.new( delay: [:delay] || 1, max_attempts: max_attempts, max_delay: max_delay, ) when :none, false NoRetry.new else raise ArgumentError, "Unknown backoff strategy: #{backoff}" end end |
.from_options(**options) ⇒ RetryConfig
Create a retry config from a hash of options
50 51 52 53 54 55 56 57 |
# File 'lib/fractor/workflow/retry_config.rb', line 50 def self.(**) strategy = create_strategy(**) new( strategy: strategy, timeout: [:timeout], retryable_errors: [:retryable_errors] || [StandardError], ) end |
Instance Method Details
#delay_for(attempt) ⇒ Numeric
Calculate delay for a given attempt
37 38 39 |
# File 'lib/fractor/workflow/retry_config.rb', line 37 def delay_for(attempt) strategy.delay_for(attempt) end |
#max_attempts ⇒ Integer
Get maximum number of retry attempts
30 31 32 |
# File 'lib/fractor/workflow/retry_config.rb', line 30 def max_attempts strategy.max_attempts end |
#retryable?(error) ⇒ Boolean
Check if an error should trigger a retry
24 25 26 |
# File 'lib/fractor/workflow/retry_config.rb', line 24 def retryable?(error) retryable_errors.any? { |err_class| error.is_a?(err_class) } end |