Class: Temporal::Workflow

Inherits:
Object
  • Object
show all
Extended by:
Concerns::Executable, Testing::WorkflowOverride, ConvenienceMethods
Defined in:
lib/temporal/workflow.rb,
lib/temporal/workflow/errors.rb,
lib/temporal/workflow/future.rb,
lib/temporal/workflow/poller.rb,
lib/temporal/workflow/command.rb,
lib/temporal/workflow/context.rb,
lib/temporal/workflow/history.rb,
lib/temporal/workflow/executor.rb,
lib/temporal/workflow/dispatcher.rb,
lib/temporal/workflow/history/event.rb,
lib/temporal/workflow/state_manager.rb,
lib/temporal/workflow/execution_info.rb,
lib/temporal/workflow/history/window.rb,
lib/temporal/workflow/task_processor.rb,
lib/temporal/workflow/convenience_methods.rb,
lib/temporal/workflow/replay_aware_logger.rb,
lib/temporal/workflow/history/event_target.rb,
lib/temporal/workflow/command_state_machine.rb

Defined Under Namespace

Modules: Command, ConvenienceMethods Classes: CommandStateMachine, Context, Dispatcher, Errors, ExecutionInfo, Executor, Future, History, Poller, ReplayAwareLogger, StateManager, TaskProcessor

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Concerns::Executable

headers, namespace, retry_policy, task_list, task_queue, timeouts

Methods included from ConvenienceMethods

execute!

Methods included from Testing::WorkflowOverride

allow_all_releases, allow_release, disable_release, disabled_releases, execute_locally

Constructor Details

#initialize(context) ⇒ Workflow

Returns a new instance of Workflow.



30
31
32
# File 'lib/temporal/workflow.rb', line 30

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
# File 'lib/temporal/workflow.rb', line 11

def self.execute_in_context(context, input)
  old_context = Temporal::ThreadLocalContext.get
  Temporal::ThreadLocalContext.set(context)

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

  context.complete(result) unless context.completed?
rescue StandardError, ScriptError => error
  Temporal.logger.error("Workflow execution failed", context..to_h.merge(error: error.inspect))
  Temporal.logger.debug(error.backtrace.join("\n"))

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

  context.fail(error)
ensure
  Temporal::ThreadLocalContext.set(old_context)
end

Instance Method Details

#executeObject

Raises:

  • (NotImplementedError)


34
35
36
# File 'lib/temporal/workflow.rb', line 34

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