global

def backoff(attempt, base_backoff)

Returns:
  • (Float) - The duration in seconds to wait before retrying

Parameters:
  • base_backoff (Float) -- The base backoff time in seconds
  • attempt (Integer) -- The current attempt number
def backoff(attempt, base_backoff)
  # Double the base backoff time per attempt, starting with 1
  exp = 2**attempt
  # Add a full jitter to the backoff time, from no wait to 100% of the exponential backoff.
  # See https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/
  jitter = rand
  (exp * jitter * base_backoff)
end