Module: CMDx::Retriers::Exponential Private

Extended by:
Exponential
Included in:
Exponential
Defined in:
lib/cmdx/retriers/exponential.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.

Exponential backoff. Doubles the base delay every attempt: ‘delay * (2 ** attempt)`. The shift is saturated at MAX_SHIFT to keep the math (and resulting sleep) bounded; pair with `:max_delay` to set the true upper bound.

Constant Summary collapse

MAX_SHIFT =

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 doubling exponent. ‘2 ** 30 ≈ 1.07e9` so paired with any sensible base delay the unclamped result is large enough to be noticed but never blows up into Bignum allocations or `Infinity`.

30

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



24
25
26
27
# File 'lib/cmdx/retriers/exponential.rb', line 24

def call(attempt, delay, _prev_delay = nil)
  shift = [attempt, MAX_SHIFT].min
  delay * (1 << shift)
end