Class: Nfe::Http::RetryPolicy
- Inherits:
-
Data
- Object
- Data
- Nfe::Http::RetryPolicy
- Defined in:
- lib/nfe/http/retry_policy.rb,
sig/nfe/http/retry_policy.rbs
Overview
Immutable retry policy describing exponential backoff with symmetric jitter. Consumed by RetryingTransport to decide how long to wait between attempts.
max_retries is the number of retries after the initial attempt, so a
policy with max_retries: 3 makes at most four HTTP attempts.
Use the RetryPolicy.default factory for the recommended settings, or RetryPolicy.none to disable retries entirely (exactly one HTTP attempt).
Instance Attribute Summary collapse
-
#base_delay ⇒ Float
readonly
Returns the value of attribute base_delay.
-
#jitter ⇒ Float
readonly
Returns the value of attribute jitter.
-
#max_delay ⇒ Float
readonly
Returns the value of attribute max_delay.
-
#max_retries ⇒ Integer
readonly
Returns the value of attribute max_retries.
Class Method Summary collapse
-
.default ⇒ RetryPolicy
Recommended defaults: 3 retries, 1s base, 30s cap, +/-30% jitter.
- .new ⇒ RetryPolicy
-
.none ⇒ RetryPolicy
No retries: exactly one HTTP attempt, zero delay.
Instance Method Summary collapse
-
#delay_for(attempt) ⇒ Float
Delay in seconds before the given (1-based) retry
attempt. -
#initialize ⇒ RetryPolicy
constructor
A new instance of RetryPolicy.
Constructor Details
#initialize ⇒ RetryPolicy
Returns a new instance of RetryPolicy.
10 |
# File 'sig/nfe/http/retry_policy.rbs', line 10
def initialize: (max_retries: Integer, base_delay: Float, max_delay: Float, jitter: Float) -> void
|
Instance Attribute Details
#base_delay ⇒ Float (readonly)
Returns the value of attribute base_delay.
5 6 7 |
# File 'sig/nfe/http/retry_policy.rbs', line 5 def base_delay @base_delay end |
#jitter ⇒ Float (readonly)
Returns the value of attribute jitter.
7 8 9 |
# File 'sig/nfe/http/retry_policy.rbs', line 7 def jitter @jitter end |
#max_delay ⇒ Float (readonly)
Returns the value of attribute max_delay.
6 7 8 |
# File 'sig/nfe/http/retry_policy.rbs', line 6 def max_delay @max_delay end |
#max_retries ⇒ Integer (readonly)
Returns the value of attribute max_retries.
4 5 6 |
# File 'sig/nfe/http/retry_policy.rbs', line 4 def max_retries @max_retries end |
Class Method Details
.default ⇒ RetryPolicy
Recommended defaults: 3 retries, 1s base, 30s cap, +/-30% jitter.
16 17 18 |
# File 'lib/nfe/http/retry_policy.rb', line 16 def self.default new(max_retries: 3, base_delay: 1.0, max_delay: 30.0, jitter: 0.3) end |
.new ⇒ RetryPolicy
9 |
# File 'sig/nfe/http/retry_policy.rbs', line 9
def self.new: (max_retries: Integer, base_delay: Float, max_delay: Float, jitter: Float) -> RetryPolicy
|
.none ⇒ RetryPolicy
No retries: exactly one HTTP attempt, zero delay.
21 22 23 |
# File 'lib/nfe/http/retry_policy.rb', line 21 def self.none new(max_retries: 0, base_delay: 0.0, max_delay: 0.0, jitter: 0.0) end |
Instance Method Details
#delay_for(attempt) ⇒ Float
Delay in seconds before the given (1-based) retry attempt.
Computes min(max_delay, base_delay * 2**(attempt - 1)) then applies
symmetric jitter, with the final value capped at max_delay.
32 33 34 35 36 |
# File 'lib/nfe/http/retry_policy.rb', line 32 def delay_for(attempt) base = [base_delay * (2**(attempt - 1)), max_delay].min jittered = base * (1 - jitter + (2 * jitter * rand)) [jittered, max_delay].min end |