Class: Fluent::PluginHelper::RetryState::ExponentialBackOffRetry
- Inherits:
-
RetryStateMachine
- Object
- RetryStateMachine
- Fluent::PluginHelper::RetryState::ExponentialBackOffRetry
- Defined in:
- lib/fluent/plugin_helper/retry_state.rb
Instance Attribute Summary
Attributes inherited from RetryStateMachine
#current, #next_time, #secondary_transition_at, #secondary_transition_steps, #start, #steps, #timeout_at, #title
Instance Method Summary collapse
- #calc_interval(num) ⇒ Object
- #calc_max_retry_timeout(max_steps) ⇒ Object
-
#initialize(title, wait, timeout, forever, max_steps, randomize, randomize_width, backoff_base, max_interval, secondary, secondary_threshold) ⇒ ExponentialBackOffRetry
constructor
A new instance of ExponentialBackOffRetry.
- #naive_next_time(retry_next_times) ⇒ Object
- #raw_interval(num) ⇒ Object
Methods inherited from RetryStateMachine
#calc_next_time, #current_time, #limit?, #randomize, #recalc_next_time, #secondary?, #step
Constructor Details
#initialize(title, wait, timeout, forever, max_steps, randomize, randomize_width, backoff_base, max_interval, secondary, secondary_threshold) ⇒ ExponentialBackOffRetry
Returns a new instance of ExponentialBackOffRetry.
154 155 156 157 158 159 160 161 162 |
# File 'lib/fluent/plugin_helper/retry_state.rb', line 154 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 |
Instance Method Details
#calc_interval(num) ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
# File 'lib/fluent/plugin_helper/retry_state.rb', line 177 def calc_interval(num) interval = raw_interval(num) 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) end interval end end end |
#calc_max_retry_timeout(max_steps) ⇒ Object
169 170 171 172 173 174 175 |
# File 'lib/fluent/plugin_helper/retry_state.rb', line 169 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) ⇒ Object
164 165 166 167 |
# File 'lib/fluent/plugin_helper/retry_state.rb', line 164 def naive_next_time(retry_next_times) intr = calc_interval(retry_next_times) current_time + randomize(intr) end |
#raw_interval(num) ⇒ Object
195 196 197 |
# File 'lib/fluent/plugin_helper/retry_state.rb', line 195 def raw_interval(num) @constant_factor.to_f * (@backoff_base ** (num)) end |