class Fluent::PluginHelper::RetryState::ExponentialBackOffRetry

Public Class Methods

new(title, wait, timeout, forever, max_steps, randomize, randomize_width, backoff_base, max_interval, secondary, secondary_threshold) click to toggle source
# File lib/fluent/plugin_helper/retry_state.rb, line 144
def initialize(title, wait, timeout, forever, max_steps, randomize, randomize_width, backoff_base, max_interval, secondary, secondary_threshold)
  @constant_factor = wait
  @backoff_base = backoff_base
  @max_interval = max_interval

  super(title, wait, timeout, forever, max_steps, randomize, randomize_width, secondary, secondary_threshold)

  @next_time = @start + @constant_factor
end

Public Instance Methods

calc_interval(num) click to toggle source
# File lib/fluent/plugin_helper/retry_state.rb, line 167
def calc_interval(num)
  interval = raw_interval(num - 1)
  if @max_interval && interval > @max_interval
    @max_interval
  else
    if interval.finite?
      interval
    else
      # Calculate previous finite value to avoid inf related errors. If this re-computing is heavy, use cache.
      until interval.finite?
        num -= 1
        interval = raw_interval(num - 1)
      end
      interval
    end
  end
end
calc_max_retry_timeout(max_steps) click to toggle source
# File lib/fluent/plugin_helper/retry_state.rb, line 159
def calc_max_retry_timeout(max_steps)
  result = 0
  max_steps.times { |i|
    result += calc_interval(i)
  }
  result
end
naive_next_time(retry_next_times) click to toggle source
# File lib/fluent/plugin_helper/retry_state.rb, line 154
def naive_next_time(retry_next_times)
  intr = calc_interval(retry_next_times)
  current_time + randomize(intr)
end
raw_interval(num) click to toggle source
# File lib/fluent/plugin_helper/retry_state.rb, line 185
def raw_interval(num)
  @constant_factor.to_f * (@backoff_base ** (num))
end