class Take2::Backoff
Attributes
factor[R]
intervals[R]
retries[R]
start[R]
type[R]
Public Class Methods
new(type, start = 1, factor = 1, retries = 10)
click to toggle source
# File lib/take2/backoff.rb, line 7 def initialize(type, start = 1, factor = 1, retries = 10) @type = type @start = start.to_i @retries = retries @factor = factor @intervals = intervals_table end
Private Instance Methods
constant()
click to toggle source
# File lib/take2/backoff.rb, line 21 def constant Array.new(retries, start) end
exponential()
click to toggle source
# File lib/take2/backoff.rb, line 33 def exponential (1..20).each_with_index.inject([]) do |memo, (el, ix)| memo << if ix == 0 start else (2**el - 1) + rand(1..2**el) end end.take(retries) end
fibo(n, memo = {})
click to toggle source
# File lib/take2/backoff.rb, line 43 def fibo(n, memo = {}) return n if n < 2 memo[n] ||= fibo(n - 1, memo) + fibo(n - 2, memo) end
fibonacci()
click to toggle source
# File lib/take2/backoff.rb, line 29 def fibonacci (1..20).map { |i| fibo(i) }.partition { |x| x >= start }.first.take(retries) end
intervals_table()
click to toggle source
# File lib/take2/backoff.rb, line 17 def intervals_table send(type) end
linear()
click to toggle source
# File lib/take2/backoff.rb, line 25 def linear (start...(retries + start)).map { |i| i * factor } end