lib/floe/workflow/state.rb in floe-0.15.0 vs lib/floe/workflow/state.rb in floe-0.15.1

- old
+ new

@@ -1,11 +1,10 @@ # frozen_string_literal: true module Floe class Workflow class State - include Logging include ValidationMixin class << self def build!(workflow, name, payload) state_type = payload["Type"] @@ -54,29 +53,37 @@ def start(context) mark_started(context) end + def started?(context) + context.state_started? + end + def finish(context) mark_finished(context) end + def finished?(context) + context.state_finished? + end + def mark_started(context) context.state["EnteredTime"] = Time.now.utc.iso8601 - logger.info("Running state: [#{long_name}] with input [#{context.json_input}]...") + context.logger.info("Running state: [#{long_name}] with input [#{context.json_input}]...") end def mark_finished(context) finished_time = Time.now.utc entered_time = Time.parse(context.state["EnteredTime"]) context.state["FinishedTime"] ||= finished_time.iso8601 context.state["Duration"] = finished_time - entered_time level = context.failed? ? :error : :info - logger.public_send(level, "Running state: [#{long_name}] with input [#{context.json_input}]...Complete #{context.next_state ? "- next state [#{context.next_state}]" : "workflow -"} output: [#{context.json_output}]") + context.logger.public_send(level, "Running state: [#{long_name}] with input [#{context.json_input}]...Complete #{context.next_state ? "- next state [#{context.next_state}]" : "workflow -"} output: [#{context.json_output}]") 0 end def mark_error(context, exception) @@ -86,10 +93,10 @@ # Since finish threw an exception, super was never called. Calling that now. mark_finished(context) end def ready?(context) - !context.state_started? || !running?(context) + !started?(context) || !running?(context) end def running?(context) raise NotImplementedError, "Must be implemented in a subclass" end