Class: Greenjaguar::Strategies::ExponentialBackoffStrategy
- Inherits:
-
WaitStrategy
- Object
- WaitStrategy
- Greenjaguar::Strategies::ExponentialBackoffStrategy
- Defined in:
- lib/greenjaguar/strategies/exponential_backoff_strategy.rb
Instance Attribute Summary
Attributes inherited from WaitStrategy
Instance Method Summary collapse
-
#initialize ⇒ ExponentialBackoffStrategy
constructor
A new instance of ExponentialBackoffStrategy.
- #reset_vars ⇒ Object
- #wait ⇒ Object
Methods inherited from WaitStrategy
Constructor Details
#initialize ⇒ ExponentialBackoffStrategy
Returns a new instance of ExponentialBackoffStrategy.
4 5 6 7 8 9 |
# File 'lib/greenjaguar/strategies/exponential_backoff_strategy.rb', line 4 def initialize super @retry_interval = 0.5 @randomization_factor = 0.5 @retry_count = 0 end |
Instance Method Details
#reset_vars ⇒ Object
11 12 13 14 |
# File 'lib/greenjaguar/strategies/exponential_backoff_strategy.rb', line 11 def reset_vars @retry_interval = 0.5 * convert_to(time_unit) @randomization_factor = 0.5 end |
#wait ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/greenjaguar/strategies/exponential_backoff_strategy.rb', line 16 def wait sleep @retry_interval @retry_count += 1 increment = (2 ** @retry_count - 1) * ([1 - @randomization_factor, 1 + @randomization_factor][random_index]) @retry_interval += increment * convert_to(time_unit) end |