Class: Greenjaguar::Strategies::ExponentialBackoffStrategy

Inherits:
WaitStrategy
  • Object
show all
Defined in:
lib/greenjaguar/strategies/exponential_backoff_strategy.rb

Instance Attribute Summary

Attributes inherited from WaitStrategy

#time_unit

Instance Method Summary collapse

Methods inherited from WaitStrategy

#convert_to

Constructor Details

#initializeExponentialBackoffStrategy

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_varsObject



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

#waitObject



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