class Fluent::PluginHelper::RetryState::RetryStateMachine
Attributes
current[R]
next_time[R]
secondary_transition_at[R]
secondary_transition_steps[R]
start[R]
steps[R]
timeout_at[R]
title[R]
Public Class Methods
new(title, wait, timeout, forever, max_steps, randomize, randomize_width, secondary, secondary_threshold)
click to toggle source
# File lib/fluent/plugin_helper/retry_state.rb, line 38 def initialize(title, wait, timeout, forever, max_steps, randomize, randomize_width, secondary, secondary_threshold) @title = title @start = current_time @steps = 0 @next_time = nil # should be initialized for first retry by child class @timeout = timeout @timeout_at = @start + timeout @current = :primary if randomize_width < 0 || randomize_width > 0.5 raise "BUG: randomize_width MUST be between 0 and 0.5" end @randomize = randomize @randomize_width = randomize_width if forever && secondary raise "BUG: forever and secondary are exclusive to each other" end @forever = forever @max_steps = max_steps @secondary = secondary @secondary_threshold = secondary_threshold if @secondary raise "BUG: secondary_transition_threshold MUST be between 0 and 1" if @secondary_threshold <= 0 || @secondary_threshold >= 1 @secondary_transition_at = @start + timeout * @secondary_threshold @secondary_transition_steps = nil end end
Public Instance Methods
calc_next_time()
click to toggle source
# File lib/fluent/plugin_helper/retry_state.rb, line 82 def calc_next_time if @forever || !@secondary # primary naive = naive_next_time(@steps) if @forever naive elsif naive >= @timeout_at @timeout_at else naive end elsif @current == :primary && @secondary naive = naive_next_time(@steps) if naive >= @secondary_transition_at @secondary_transition_at else naive end elsif @current == :secondary naive = naive_next_time(@steps - @secondary_transition_steps + 1) if naive >= @timeout_at @timeout_at else naive end else raise "BUG: it's out of design" end end
current_time()
click to toggle source
# File lib/fluent/plugin_helper/retry_state.rb, line 72 def current_time Time.now end
limit?()
click to toggle source
# File lib/fluent/plugin_helper/retry_state.rb, line 129 def limit? if @forever false else @next_time >= @timeout_at || !!(@max_steps && @steps >= @max_steps) end end
naive_next_time(retry_times)
click to toggle source
# File lib/fluent/plugin_helper/retry_state.rb, line 111 def naive_next_time(retry_times) raise NotImplementedError end
randomize(interval)
click to toggle source
# File lib/fluent/plugin_helper/retry_state.rb, line 76 def randomize(interval) return interval unless @randomize interval + (interval * @randomize_width * (2 * rand - 1.0)) end
secondary?()
click to toggle source
# File lib/fluent/plugin_helper/retry_state.rb, line 115 def secondary? @secondary && (@current == :secondary || current_time >= @secondary_transition_at) end
step()
click to toggle source
# File lib/fluent/plugin_helper/retry_state.rb, line 119 def step @steps += 1 if @secondary && @current != :secondary && current_time >= @secondary_transition_at @current = :secondary @secondary_transition_steps = @steps end @next_time = calc_next_time nil end