Class: Dynamoid::Config::BackoffStrategies::ExponentialBackoff

Inherits:
Object
  • Object
show all
Defined in:
lib/dynamoid/config/backoff_strategies/exponential_backoff.rb

Overview

Truncated binary exponential backoff algorithm See en.wikipedia.org/wiki/Exponential_backoff

Class Method Summary collapse

Class Method Details

.call(opts = {}) ⇒ Object


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/dynamoid/config/backoff_strategies/exponential_backoff.rb', line 10

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