Class: Temporalio::Internal::Worker::WorkflowInstance::NexusOperationHandle

Inherits:
Workflow::NexusOperationHandle show all
Defined in:
lib/temporalio/internal/worker/workflow_instance/nexus_operation_handle.rb

Overview

Implementation of the Nexus operation handle.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(operation_token:, instance:, cancellation:, cancel_callback_key:, result_hint:) ⇒ NexusOperationHandle

rubocop:disable Lint/MissingSuper



15
16
17
18
19
20
21
22
23
# File 'lib/temporalio/internal/worker/workflow_instance/nexus_operation_handle.rb', line 15

def initialize(operation_token:, instance:, cancellation:, cancel_callback_key:, # rubocop:disable Lint/MissingSuper
               result_hint:)
  @operation_token = operation_token
  @instance = instance
  @cancellation = cancellation
  @cancel_callback_key = cancel_callback_key
  @result_hint = result_hint
  @resolution = nil
end

Instance Attribute Details

#operation_tokenObject (readonly)

Returns the value of attribute operation_token.



13
14
15
# File 'lib/temporalio/internal/worker/workflow_instance/nexus_operation_handle.rb', line 13

def operation_token
  @operation_token
end

#result_hintObject (readonly)

Returns the value of attribute result_hint.



13
14
15
# File 'lib/temporalio/internal/worker/workflow_instance/nexus_operation_handle.rb', line 13

def result_hint
  @result_hint
end

Instance Method Details

#_resolve(resolution) ⇒ Object



43
44
45
46
# File 'lib/temporalio/internal/worker/workflow_instance/nexus_operation_handle.rb', line 43

def _resolve(resolution)
  @cancellation.remove_cancel_callback(@cancel_callback_key)
  @resolution = resolution
end

#result(result_hint: nil) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/temporalio/internal/worker/workflow_instance/nexus_operation_handle.rb', line 25

def result(result_hint: nil)
  # Use detached cancellation like child workflow to avoid interrupting result wait
  Workflow.wait_condition(cancellation: Cancellation.new) { @resolution }

  case @resolution.status
  when :completed
    @instance.payload_converter.from_payload(@resolution.completed, hint: result_hint || @result_hint)
  when :failed
    raise @instance.failure_converter.from_failure(@resolution.failed, @instance.payload_converter)
  when :cancelled
    raise @instance.failure_converter.from_failure(@resolution.cancelled, @instance.payload_converter)
  when :timed_out
    raise @instance.failure_converter.from_failure(@resolution.timed_out, @instance.payload_converter)
  else
    raise "Unrecognized Nexus operation result status: #{@resolution.status}"
  end
end