Class: Sendmux::Core::RetryOptions
- Inherits:
-
Object
- Object
- Sendmux::Core::RetryOptions
- Defined in:
- lib/sendmux/core/retry_options.rb
Constant Summary collapse
- RETRY_STATUSES =
[408, 409, 425, 429, 500, 502, 503, 504].freeze
Instance Attribute Summary collapse
-
#base_delay_seconds ⇒ Object
readonly
Returns the value of attribute base_delay_seconds.
-
#jitter ⇒ Object
readonly
Returns the value of attribute jitter.
-
#max_attempts ⇒ Object
readonly
Returns the value of attribute max_attempts.
-
#max_delay_seconds ⇒ Object
readonly
Returns the value of attribute max_delay_seconds.
Instance Method Summary collapse
-
#initialize(max_attempts: 3, base_delay_seconds: 0.25, max_delay_seconds: 5.0, jitter: true) ⇒ RetryOptions
constructor
A new instance of RetryOptions.
- #to_faraday_options ⇒ Object
Constructor Details
#initialize(max_attempts: 3, base_delay_seconds: 0.25, max_delay_seconds: 5.0, jitter: true) ⇒ RetryOptions
Returns a new instance of RetryOptions.
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/sendmux/core/retry_options.rb', line 10 def initialize(max_attempts: 3, base_delay_seconds: 0.25, max_delay_seconds: 5.0, jitter: true) raise ArgumentError, 'max_attempts must be at least 1' if max_attempts < 1 if base_delay_seconds.negative? || max_delay_seconds.negative? raise ArgumentError, 'retry delays must be non-negative' end @max_attempts = max_attempts @base_delay_seconds = base_delay_seconds @max_delay_seconds = max_delay_seconds @jitter = jitter end |
Instance Attribute Details
#base_delay_seconds ⇒ Object (readonly)
Returns the value of attribute base_delay_seconds.
8 9 10 |
# File 'lib/sendmux/core/retry_options.rb', line 8 def base_delay_seconds @base_delay_seconds end |
#jitter ⇒ Object (readonly)
Returns the value of attribute jitter.
8 9 10 |
# File 'lib/sendmux/core/retry_options.rb', line 8 def jitter @jitter end |
#max_attempts ⇒ Object (readonly)
Returns the value of attribute max_attempts.
8 9 10 |
# File 'lib/sendmux/core/retry_options.rb', line 8 def max_attempts @max_attempts end |
#max_delay_seconds ⇒ Object (readonly)
Returns the value of attribute max_delay_seconds.
8 9 10 |
# File 'lib/sendmux/core/retry_options.rb', line 8 def max_delay_seconds @max_delay_seconds end |
Instance Method Details
#to_faraday_options ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/sendmux/core/retry_options.rb', line 23 def { max: max_attempts - 1, interval: base_delay_seconds, max_interval: max_delay_seconds, interval_randomness: jitter ? 0.5 : 0.0, backoff_factor: 2, methods: [], retry_statuses: RETRY_STATUSES, rate_limit_retry_header: 'Retry-After', rate_limit_reset_header: 'X-RateLimit-Reset', retry_if: ->(env, _exception) { Retry.retryable_request?(env) } } end |