Class: R2::Retry::Policy
- Inherits:
-
Object
- Object
- R2::Retry::Policy
- Defined in:
- lib/r2/retry.rb
Overview
Retry settings shared by the operations of a client.
Instance Attribute Summary collapse
-
#base_delay ⇒ Object
readonly
Returns the value of attribute base_delay.
-
#max_attempts ⇒ Object
readonly
Returns the value of attribute max_attempts.
-
#max_delay ⇒ Object
readonly
Returns the value of attribute max_delay.
Instance Method Summary collapse
-
#delay_for(attempt) ⇒ Float
Wait applied after the given failed attempt.
-
#initialize(max_attempts: DEFAULT_MAX_ATTEMPTS, base_delay: DEFAULT_BASE_DELAY, max_delay: DEFAULT_MAX_DELAY) ⇒ Policy
constructor
A new instance of Policy.
Constructor Details
#initialize(max_attempts: DEFAULT_MAX_ATTEMPTS, base_delay: DEFAULT_BASE_DELAY, max_delay: DEFAULT_MAX_DELAY) ⇒ Policy
Returns a new instance of Policy.
36 37 38 39 40 41 42 43 44 |
# File 'lib/r2/retry.rb', line 36 def initialize( max_attempts: DEFAULT_MAX_ATTEMPTS, base_delay: DEFAULT_BASE_DELAY, max_delay: DEFAULT_MAX_DELAY ) @max_attempts = max_attempts @base_delay = base_delay @max_delay = max_delay end |
Instance Attribute Details
#base_delay ⇒ Object (readonly)
Returns the value of attribute base_delay.
31 32 33 |
# File 'lib/r2/retry.rb', line 31 def base_delay @base_delay end |
#max_attempts ⇒ Object (readonly)
Returns the value of attribute max_attempts.
31 32 33 |
# File 'lib/r2/retry.rb', line 31 def max_attempts @max_attempts end |
#max_delay ⇒ Object (readonly)
Returns the value of attribute max_delay.
31 32 33 |
# File 'lib/r2/retry.rb', line 31 def max_delay @max_delay end |
Instance Method Details
#delay_for(attempt) ⇒ Float
Wait applied after the given failed attempt.
50 51 52 |
# File 'lib/r2/retry.rb', line 50 def delay_for(attempt) [@base_delay * (2**(attempt - 1)), @max_delay].min end |