Class: Fractor::Workflow::ExponentialBackoff

Inherits:
RetryStrategy show all
Defined in:
lib/fractor/workflow/retry_strategy.rb

Overview

Exponential backoff retry strategy

Instance Attribute Summary collapse

Attributes inherited from RetryStrategy

#max_attempts, #max_delay

Instance Method Summary collapse

Constructor Details

#initialize(initial_delay: 1, multiplier: 2, **options) ⇒ ExponentialBackoff

Returns a new instance of ExponentialBackoff.



34
35
36
37
38
# File 'lib/fractor/workflow/retry_strategy.rb', line 34

def initialize(initial_delay: 1, multiplier: 2, **options)
  super(**options)
  @initial_delay = initial_delay
  @multiplier = multiplier
end

Instance Attribute Details

#initial_delayObject (readonly)

Returns the value of attribute initial_delay.



32
33
34
# File 'lib/fractor/workflow/retry_strategy.rb', line 32

def initial_delay
  @initial_delay
end

#multiplierObject (readonly)

Returns the value of attribute multiplier.



32
33
34
# File 'lib/fractor/workflow/retry_strategy.rb', line 32

def multiplier
  @multiplier
end

Instance Method Details

#delay_for(attempt) ⇒ Object



40
41
42
43
44
45
# File 'lib/fractor/workflow/retry_strategy.rb', line 40

def delay_for(attempt)
  return 0 if attempt <= 1

  delay = initial_delay * (multiplier**(attempt - 2))
  cap_delay(delay)
end