Sha256: 02be131014deec44a601fd505cf7bcc25a4d97fddec8845839732fcc5f52b670
Contents?: true
Size: 674 Bytes
Versions: 7
Compression:
Stored size: 674 Bytes
Contents
# frozen_string_literal: true module Dynamoid module Config # @private module BackoffStrategies # Truncated binary exponential backoff algorithm # See https://en.wikipedia.org/wiki/Exponential_backoff class ExponentialBackoff def self.call(opts = {}) opts = { base_backoff: 0.5, ceiling: 3 }.merge(opts) base_backoff = opts[:base_backoff] ceiling = opts[:ceiling] times = 1 lambda do power = [times - 1, ceiling - 1].min backoff = base_backoff * (2**power) sleep backoff times += 1 end end end end end end
Version data entries
7 entries across 7 versions & 1 rubygems