Module: Floe::Workflow::States::RetryCatchMixin

Included in:
Map, Parallel, Task
Defined in:
lib/floe/workflow/states/retry_catch_mixin.rb

Instance Method Summary collapse

Instance Method Details

#catch_error!(context, error) ⇒ Object



36
37
38
39
40
41
42
43
44
45
# File 'lib/floe/workflow/states/retry_catch_mixin.rb', line 36

def catch_error!(context, error)
  catcher = find_catcher(error["Error"]) if error
  return if catcher.nil?

  context.next_state = catcher.next
  context.output     = catcher.result_path.set(context.input, error)
  context.logger.info("Running state: [#{long_name}] with input [#{context.json_input}]...CatchError - next state: [#{context.next_state}] output: [#{context.json_output}]")

  true
end

#fail_workflow!(context, error) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/floe/workflow/states/retry_catch_mixin.rb', line 47

def fail_workflow!(context, error)
  # next_state is nil, and will be set to nil again in super
  # keeping in here for completeness
  context.next_state = nil
  context.output = error
  context.logger.error("Running state: [#{long_name}] with input [#{context.json_input}]...Complete workflow - output: [#{context.json_output}]")
end

#find_catcher(error) ⇒ Object



11
12
13
# File 'lib/floe/workflow/states/retry_catch_mixin.rb', line 11

def find_catcher(error)
  self.catch.detect { |c| c.match_error?(error) }
end

#find_retrier(error) ⇒ Object



7
8
9
# File 'lib/floe/workflow/states/retry_catch_mixin.rb', line 7

def find_retrier(error)
  self.retry.detect { |r| r.match_error?(error) }
end

#retry_state!(context, error) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/floe/workflow/states/retry_catch_mixin.rb', line 15

def retry_state!(context, error)
  retrier = find_retrier(error["Error"]) if error
  return if retrier.nil?

  # If a different retrier is hit reset the context
  if !context["State"].key?("RetryCount") || context["State"]["Retrier"] != retrier.error_equals
    context["State"]["RetryCount"] = 0
    context["State"]["Retrier"]    = retrier.error_equals
  end

  context["State"]["RetryCount"] += 1

  return if context["State"]["RetryCount"] > retrier.max_attempts

  wait_until!(context, :seconds => retrier.sleep_duration(context["State"]["RetryCount"]))
  context.next_state = context.state_name
  context.output     = error
  context.logger.info("Running state: [#{long_name}] with input [#{context.json_input}] got error[#{context.json_output}]...Retry - delay: #{wait_until(context)}")
  true
end