Class: Fractor::Workflow::LinearBackoff

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

Overview

Linear 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, increment: 1, **options) ⇒ LinearBackoff

Returns a new instance of LinearBackoff.



52
53
54
55
56
# File 'lib/fractor/workflow/retry_strategy.rb', line 52

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

Instance Attribute Details

#incrementObject (readonly)

Returns the value of attribute increment.



50
51
52
# File 'lib/fractor/workflow/retry_strategy.rb', line 50

def increment
  @increment
end

#initial_delayObject (readonly)

Returns the value of attribute initial_delay.



50
51
52
# File 'lib/fractor/workflow/retry_strategy.rb', line 50

def initial_delay
  @initial_delay
end

Instance Method Details

#delay_for(attempt) ⇒ Object



58
59
60
61
62
63
# File 'lib/fractor/workflow/retry_strategy.rb', line 58

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

  delay = initial_delay + (increment * (attempt - 2))
  cap_delay(delay)
end