Module: CMDx::Retriers::DecorrelatedJitter Private

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

AWS-recommended decorrelated jitter. Produces a uniform delay in ‘[delay, prev_delay * 3]`, threading state across attempts via `prev_delay`. When no previous delay exists the upper bound collapses to `3 * delay`, matching the AWS reference implementation.

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)

    ignored

  • delay (Float)

    base delay in seconds (also the lower bound)

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

    previous computed delay; falls back to ‘delay` so the first call samples in `[delay, 3*delay]`

Returns:

  • (Float)

    computed delay



21
22
23
24
# File 'lib/cmdx/retriers/decorrelated_jitter.rb', line 21

def call(_attempt, delay, prev_delay = nil)
  base = prev_delay || delay
  delay + (rand * ((base * 3) - delay))
end