Module: CMDx::Retriers::Fibonacci Private

Extended by:
Fibonacci
Included in:
Fibonacci
Defined in:
lib/cmdx/retriers/fibonacci.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Fibonacci backoff. Sleeps ‘delay * fib(attempt + 1)` where `fib(1) == 1`, `fib(2) == 1`, `fib(3) == 2`, … Multipliers grow as 1, 1, 2, 3, 5, 8. Slower-growing than exponential, faster-growing than linear.

Constant Summary collapse

MAX_INDEX =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Hard cap on the index to keep multipliers/integer allocations bounded. ‘fib(78) < 2**63`, well past any realistic retry attempt. Pair with `:max_delay` for the actual sleep ceiling.

78

Instance Method Summary collapse

Instance Method Details

#call(attempt, delay, _prev_delay = nil) ⇒ Float

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns computed delay.

Parameters:

  • attempt (Integer)

    zero-based retry attempt

  • delay (Float)

    base delay in seconds

  • _prev_delay (Float, nil) (defaults to: nil)

    ignored

Returns:

  • (Float)

    computed delay



30
31
32
33
34
# File 'lib/cmdx/retriers/fibonacci.rb', line 30

def call(attempt, delay, _prev_delay = nil)
  index = attempt + 1
  index = MAX_INDEX if index > MAX_INDEX
  delay * fib(index)
end