class Greenjaguar::Strategies::ExponentialBackoffStrategy

Public Class Methods

new() click to toggle source
Calls superclass method
# 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

Public Instance Methods

reset_vars() click to toggle source
# 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() click to toggle source
# 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

Private Instance Methods

random_index() click to toggle source
# File lib/greenjaguar/strategies/exponential_backoff_strategy.rb, line 25
def random_index
  rand(2)
end