Class: Cadence::Workflow

Inherits:
Object
  • Object
show all
Extended by:
Concerns::Executable, ConvenienceMethods
Defined in:
lib/cadence/workflow.rb,
lib/cadence/workflow/future.rb,
lib/cadence/workflow/poller.rb,
lib/cadence/workflow/status.rb,
lib/cadence/workflow/context.rb,
lib/cadence/workflow/history.rb,
lib/cadence/workflow/decision.rb,
lib/cadence/workflow/executor.rb,
lib/cadence/workflow/dispatcher.rb,
lib/cadence/workflow/serializer.rb,
lib/cadence/workflow/history/event.rb,
lib/cadence/workflow/state_manager.rb,
lib/cadence/workflow/execution_info.rb,
lib/cadence/workflow/history/window.rb,
lib/cadence/workflow/serializer/base.rb,
lib/cadence/workflow/convenience_methods.rb,
lib/cadence/workflow/replay_aware_logger.rb,
lib/cadence/workflow/history/event_target.rb,
lib/cadence/workflow/decision_state_machine.rb,
lib/cadence/workflow/serializer/start_timer.rb,
lib/cadence/workflow/decision_task_processor.rb,
lib/cadence/workflow/serializer/cancel_timer.rb,
lib/cadence/workflow/serializer/fail_workflow.rb,
lib/cadence/workflow/serializer/record_marker.rb,
lib/cadence/workflow/serializer/complete_workflow.rb,
lib/cadence/workflow/serializer/schedule_activity.rb,
lib/cadence/workflow/serializer/start_child_workflow.rb,
lib/cadence/workflow/serializer/request_activity_cancellation.rb

Defined Under Namespace

Modules: ConvenienceMethods, Decision, Serializer, Status Classes: Context, DecisionStateMachine, DecisionTaskProcessor, Dispatcher, ExecutionInfo, Executor, Future, History, Poller, ReplayAwareLogger, StateManager

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Concerns::Executable

domain, headers, retry_policy, task_list, timeouts

Methods included from ConvenienceMethods

execute!

Constructor Details

#initialize(context) ⇒ Workflow

Returns a new instance of Workflow.


31
32
33
# File 'lib/cadence/workflow.rb', line 31

def initialize(context)
  @context = context
end

Class Method Details

.execute_in_context(context, input) ⇒ Object


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/cadence/workflow.rb', line 11

def self.execute_in_context(context, input)
  previous_context = Cadence::ThreadLocalContext.get
  Cadence::ThreadLocalContext.set(context)

  workflow = new(context)
  result = workflow.execute(*input)

  context.complete(result)
rescue StandardError, ScriptError => error
  Cadence.logger.error("Workflow execution failed with: #{error.inspect}")
  Cadence.logger.debug(error.backtrace.join("\n"))

  Cadence::ErrorHandler.handle(error, metadata: context.)

  context.fail(error.class.name, error.message)
ensure
  # Reset back to previous context for child workflows
  Cadence::ThreadLocalContext.set(previous_context) if previous_context
end

Instance Method Details

#executeObject

Raises:

  • (NotImplementedError)

35
36
37
# File 'lib/cadence/workflow.rb', line 35

def execute
  raise NotImplementedError, '#execute method must be implemented by a subclass'
end