Class: SenroUsecaser::RetryConfiguration
- Inherits:
-
Object
- Object
- SenroUsecaser::RetryConfiguration
- Defined in:
- lib/senro_usecaser/retry_configuration.rb
Overview
Configuration for automatic retry behavior
This class defines when and how retries should occur based on error codes or exception classes, with configurable backoff strategies.
Instance Attribute Summary collapse
-
#attempts ⇒ Object
readonly
Returns the maximum number of attempts : () -> Integer.
-
#backoff ⇒ Object
readonly
Returns the backoff strategy (:fixed, :linear, :exponential) : () -> Symbol.
-
#jitter ⇒ Object
readonly
Returns the jitter factor (0.0 to 1.0) : () -> (Float | Integer).
-
#matchers ⇒ Object
readonly
Returns the list of error matchers (Symbols for error codes, Classes for exceptions) : () -> Array[(Symbol | Class)].
-
#max_wait ⇒ Object
readonly
Returns the maximum wait time in seconds : () -> (Float | Integer).
-
#wait ⇒ Object
readonly
Returns the base wait time in seconds : () -> (Float | Integer).
Instance Method Summary collapse
-
#calculate_wait(attempt) ⇒ Object
Calculates the wait time for the given attempt number.
-
#initialize(matchers:, attempts: 3, wait: 0, backoff: :fixed, max_wait: nil, jitter: 0) ⇒ RetryConfiguration
constructor
Initializes a new retry configuration.
-
#matches?(result) ⇒ Boolean
Checks if this configuration matches the given result.
Constructor Details
#initialize(matchers:, attempts: 3, wait: 0, backoff: :fixed, max_wait: nil, jitter: 0) ⇒ RetryConfiguration
Initializes a new retry configuration
rubocop:disable Metrics/ParameterLists : (matchers: Array[(Symbol | Class)], ?attempts: Integer, ?wait: (Float | Integer), : ?backoff: Symbol, ?max_wait: (Float | Integer)?, ?jitter: (Float | Integer)) -> void
63 64 65 66 67 68 69 70 71 |
# File 'lib/senro_usecaser/retry_configuration.rb', line 63 def initialize(matchers:, attempts: 3, wait: 0, backoff: :fixed, max_wait: nil, jitter: 0) # rubocop:enable Metrics/ParameterLists @matchers = matchers @attempts = attempts @wait = wait @backoff = backoff @max_wait = max_wait || 3600 @jitter = jitter end |
Instance Attribute Details
#attempts ⇒ Object (readonly)
Returns the maximum number of attempts : () -> Integer
33 34 35 |
# File 'lib/senro_usecaser/retry_configuration.rb', line 33 def attempts @attempts end |
#backoff ⇒ Object (readonly)
Returns the backoff strategy (:fixed, :linear, :exponential) : () -> Symbol
41 42 43 |
# File 'lib/senro_usecaser/retry_configuration.rb', line 41 def backoff @backoff end |
#jitter ⇒ Object (readonly)
Returns the jitter factor (0.0 to 1.0) : () -> (Float | Integer)
49 50 51 |
# File 'lib/senro_usecaser/retry_configuration.rb', line 49 def jitter @jitter end |
#matchers ⇒ Object (readonly)
Returns the list of error matchers (Symbols for error codes, Classes for exceptions) : () -> Array[(Symbol | Class)]
29 30 31 |
# File 'lib/senro_usecaser/retry_configuration.rb', line 29 def matchers @matchers end |
#max_wait ⇒ Object (readonly)
Returns the maximum wait time in seconds : () -> (Float | Integer)
45 46 47 |
# File 'lib/senro_usecaser/retry_configuration.rb', line 45 def max_wait @max_wait end |
#wait ⇒ Object (readonly)
Returns the base wait time in seconds : () -> (Float | Integer)
37 38 39 |
# File 'lib/senro_usecaser/retry_configuration.rb', line 37 def wait @wait end |
Instance Method Details
#calculate_wait(attempt) ⇒ Object
Calculates the wait time for the given attempt number
: (Integer) -> Float
85 86 87 88 89 |
# File 'lib/senro_usecaser/retry_configuration.rb', line 85 def calculate_wait(attempt) base = calculate_base_wait(attempt) base = [base, @max_wait].min apply_jitter(base) end |
#matches?(result) ⇒ Boolean
Checks if this configuration matches the given result
: (Result) -> bool
76 77 78 79 80 |
# File 'lib/senro_usecaser/retry_configuration.rb', line 76 def matches?(result) return false unless result.failure? result.errors.any? { |error| matches_error?(error) } end |