Class: SplitIoClient::Engine::BackOff

Inherits:
Object
  • Object
show all
Defined in:
lib/splitclient-rb/engine/back_off.rb

Instance Method Summary collapse

Constructor Details

#initialize(back_off_base, attempt = 0, max_allowed = BACKOFF_MAX_ALLOWED) ⇒ BackOff

Returns a new instance of BackOff.



7
8
9
10
11
# File 'lib/splitclient-rb/engine/back_off.rb', line 7

def initialize(back_off_base, attempt = 0, max_allowed = BACKOFF_MAX_ALLOWED)
  @attempt = attempt
  @back_off_base = back_off_base
  @max_allowed = max_allowed
end

Instance Method Details

#intervalObject



13
14
15
16
17
18
19
# File 'lib/splitclient-rb/engine/back_off.rb', line 13

def interval
  interval = 0
  interval = (@back_off_base * (2**@attempt)) if @attempt.positive?
  @attempt += 1

  interval >= @max_allowed ? @max_allowed : interval
end

#resetObject



21
22
23
# File 'lib/splitclient-rb/engine/back_off.rb', line 21

def reset
  @attempt = 0
end