Class: Floe::Workflow::Retrier

Inherits:
Object
  • Object
show all
Includes:
ValidationMixin, ErrorMatcherMixin
Defined in:
lib/floe/workflow/retrier.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ValidationMixin

included, #invalid_field_error!, #missing_field_error!, #parser_error!, #runtime_field_error!, #workflow_state?, #wrap_parser_error

Methods included from ErrorMatcherMixin

#match_error?

Constructor Details

#initialize(_workflow, name, payload) ⇒ Retrier

Returns a new instance of Retrier.



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/floe/workflow/retrier.rb', line 11

def initialize(_workflow, name, payload)
  @name             = name
  @payload          = payload

  @error_equals     = payload["ErrorEquals"]
  @interval_seconds = payload["IntervalSeconds"] || 1.0
  @max_attempts     = payload["MaxAttempts"] || 3
  @backoff_rate     = payload["BackoffRate"] || 2.0

  missing_field_error!("ErrorEquals") if !@error_equals.kind_of?(Array) || @error_equals.empty?
end

Instance Attribute Details

#backoff_rateObject (readonly)

Returns the value of attribute backoff_rate.



9
10
11
# File 'lib/floe/workflow/retrier.rb', line 9

def backoff_rate
  @backoff_rate
end

#error_equalsObject (readonly)

Returns the value of attribute error_equals.



9
10
11
# File 'lib/floe/workflow/retrier.rb', line 9

def error_equals
  @error_equals
end

#interval_secondsObject (readonly)

Returns the value of attribute interval_seconds.



9
10
11
# File 'lib/floe/workflow/retrier.rb', line 9

def interval_seconds
  @interval_seconds
end

#max_attemptsObject (readonly)

Returns the value of attribute max_attempts.



9
10
11
# File 'lib/floe/workflow/retrier.rb', line 9

def max_attempts
  @max_attempts
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/floe/workflow/retrier.rb', line 9

def name
  @name
end

Instance Method Details

#sleep_duration(attempt) ⇒ Object

Parameters:

  • attempt (Integer)

    1 for the first attempt



24
25
26
# File 'lib/floe/workflow/retrier.rb', line 24

def sleep_duration(attempt)
  interval_seconds * (backoff_rate**(attempt - 1))
end