class Temporalio::Client::WorkflowHandle

{Client.workflow_handle}.
Handle for interacting with a workflow. This is usually created via {Client.start_workflow} or

def cancel(rpc_options: nil)

Other tags:
    Note: - Handles created as a result of signal with start will cancel the latest workflow with the same workflow ID

Raises:
  • (Error::RPCError) - RPC error from call.

Parameters:
  • rpc_options (RPCOptions, nil) -- Advanced RPC options.
def cancel(rpc_options: nil)
  @client._impl.cancel_workflow(Interceptor::CancelWorkflowInput.new(
                                  workflow_id: id,
                                  run_id:,
                                  first_execution_run_id:,
                                  rpc_options:
                                ))
end

def describe(rpc_options: nil)

Other tags:
    Note: - Handles created as a result of {Client.start_workflow} will describe the latest workflow with the same

Raises:
  • (Error::RPCError) - RPC error from call.

Returns:
  • (WorkflowExecution::Description) - Workflow description.

Parameters:
  • rpc_options (RPCOptions, nil) -- Advanced RPC options.
def describe(rpc_options: nil)
  @client._impl.describe_workflow(Interceptor::DescribeWorkflowInput.new(
                                    workflow_id: id,
                                    run_id:,
                                    rpc_options:
                                  ))
end

def execute_update(update, *args, id: SecureRandom.uuid, rpc_options: nil)

Other tags:
    Note: - Handles created as a result of {Client.start_workflow} will send updates the latest workflow with the same

Raises:
  • (Error::RPCError) - RPC error from call.
  • (Error::WorkflowUpdateRPCTimeoutOrCanceledError) - This update call timed out or was canceled. This doesn't
  • (Error::WorkflowUpdateFailedError) - If the update failed.

Returns:
  • (Object, nil) - Update result.

Parameters:
  • rpc_options (RPCOptions, nil) -- Advanced RPC options.
  • id (String) -- ID of the update.
  • args (Array) -- Update arguments.
  • update (Workflow::Definition::Update, Symbol, String) -- Update definition or name.
  • def execute_update(update, *args, id: SecureRandom.uuid, rpc_options: nil)
      start_update(
        update,
        *args,
        wait_for_stage: WorkflowUpdateWaitStage::COMPLETED,
        id:,
        rpc_options:
      ).result
    end

    def fetch_history(

    Raises:
    • (Error::RPCError) - RPC error from call.

    Returns:
    • (WorkflowHistory) - Workflow history.

    Parameters:
    • rpc_options (RPCOptions, nil) -- Advanced RPC options.
    • skip_archival (Boolean) -- Whether to skip archival.
    • event_filter_type (Api::Enums::V1::HistoryEventFilterType) -- Types of events to fetch.
    def fetch_history(
      event_filter_type: Api::Enums::V1::HistoryEventFilterType::HISTORY_EVENT_FILTER_TYPE_ALL_EVENT,
      skip_archival: false,
      rpc_options: nil
    )
      WorkflowHistory.new(
        fetch_history_events(
          event_filter_type:,
          skip_archival:,
          rpc_options:
        ).to_a
      )
    end

    def fetch_history_events(

    Raises:
    • (Error::RPCError) - RPC error from call.

    Returns:
    • (Enumerator) - Enumerable events.

    Parameters:
    • rpc_options (RPCOptions, nil) -- Advanced RPC options.
    • specific_run_id (String, nil) -- Run ID to fetch events for. Default is the {run_id}. Most users will not
    • skip_archival (Boolean) -- Whether to skip archival.
    • event_filter_type (Api::Enums::V1::HistoryEventFilterType) -- Types of events to fetch.
    • wait_new_event (Boolean) -- If +true+, when the end of the current set of events is reached but the workflow
    def fetch_history_events(
      wait_new_event: false,
      event_filter_type: Api::Enums::V1::HistoryEventFilterType::HISTORY_EVENT_FILTER_TYPE_ALL_EVENT,
      skip_archival: false,
      specific_run_id: run_id,
      rpc_options: nil
    )
      @client._impl.fetch_workflow_history_events(Interceptor::FetchWorkflowHistoryEventsInput.new(
                                                    workflow_id: id,
                                                    run_id: specific_run_id,
                                                    wait_new_event:,
                                                    event_filter_type:,
                                                    skip_archival:,
                                                    rpc_options:
                                                  ))
    end

    def initialize(client:, id:, run_id:, result_run_id:, first_execution_run_id:)

    @!visibility private
    def initialize(client:, id:, run_id:, result_run_id:, first_execution_run_id:)
      @client = client
      @id = id
      @run_id = run_id
      @result_run_id = result_run_id
      @first_execution_run_id = first_execution_run_id
    end

    def query(

    Other tags:
      Note: - Handles created as a result of {Client.start_workflow} will query the latest workflow with the same

    Raises:
    • (Error::RPCError) - RPC error from call.
    • (Error::WorkflowQueryRejectedError) - A query reject condition was satisfied.
    • (Error::WorkflowQueryFailedError) - The query on the workflow returned a failure.

    Returns:
    • (Object, nil) - Query result.

    Parameters:
    • rpc_options (RPCOptions, nil) -- Advanced RPC options.
    • reject_condition (WorkflowQueryRejectCondition, nil) -- Condition for rejecting the query.
    • args (Array) -- Query arguments.
    • query (Workflow::Definition::Query, Symbol, String) -- Query definition or name.
    • def query(
        query,
        *args,
        reject_condition: @client.options.default_workflow_query_reject_condition,
        rpc_options: nil
      )
        @client._impl.query_workflow(Interceptor::QueryWorkflowInput.new(
                                       workflow_id: id,
                                       run_id:,
                                       query:,
                                       args:,
                                       reject_condition:,
                                       headers: {},
                                       rpc_options:
                                     ))
      end

      def result(follow_runs: true, rpc_options: nil)

      Raises:
      • (Error::RPCError) - RPC error from call.
      • (Error::WorkflowContinuedAsNewError) - Workflow continued as new and +follow_runs+ is +false+.
      • (Error::WorkflowFailedError) - Workflow failed with +cause+ as the cause.

      Returns:
      • (Object) - Result of the workflow after being converted by the data converter.

      Parameters:
      • rpc_options (RPCOptions, nil) -- Advanced RPC options.
      • follow_runs (Boolean) -- If +true+, workflow runs will be continually fetched across retries and continue as
      def result(follow_runs: true, rpc_options: nil)
        # Wait on the close event, following as needed
        hist_run_id = result_run_id
        loop do
          # Get close event
          event = fetch_history_events(
            wait_new_event: true,
            event_filter_type: Api::Enums::V1::HistoryEventFilterType::HISTORY_EVENT_FILTER_TYPE_CLOSE_EVENT,
            skip_archival: true,
            specific_run_id: hist_run_id,
            rpc_options:
          ).next
          # Check each close type'
          case event.event_type
          when :EVENT_TYPE_WORKFLOW_EXECUTION_COMPLETED
            attrs = event.workflow_execution_completed_event_attributes
            hist_run_id = attrs.new_execution_run_id
            next if follow_runs && hist_run_id && !hist_run_id.empty?
            return @client.data_converter.from_payloads(attrs.result).first
          when :EVENT_TYPE_WORKFLOW_EXECUTION_FAILED
            attrs = event.workflow_execution_failed_event_attributes
            hist_run_id = attrs.new_execution_run_id
            next if follow_runs && hist_run_id && !hist_run_id.empty?
            raise Error::WorkflowFailedError.new, cause: @client.data_converter.from_failure(attrs.failure)
          when :EVENT_TYPE_WORKFLOW_EXECUTION_CANCELED
            attrs = event.workflow_execution_canceled_event_attributes
            raise Error::WorkflowFailedError.new, 'Workflow execution canceled', cause: Error::CanceledError.new(
              'Workflow execution canceled',
              details: @client.data_converter.from_payloads(attrs&.details)
            )
          when :EVENT_TYPE_WORKFLOW_EXECUTION_TERMINATED
            attrs = event.workflow_execution_terminated_event_attributes
            raise Error::WorkflowFailedError.new, 'Workflow execution terminated', cause: Error::TerminatedError.new(
              Internal::ProtoUtils.string_or(attrs.reason, 'Workflow execution terminated'),
              details: @client.data_converter.from_payloads(attrs&.details)
            )
          when :EVENT_TYPE_WORKFLOW_EXECUTION_TIMED_OUT
            attrs = event.workflow_execution_timed_out_event_attributes
            hist_run_id = attrs.new_execution_run_id
            next if follow_runs && hist_run_id && !hist_run_id.empty?
            raise Error::WorkflowFailedError.new, 'Workflow execution timed out', cause: Error::TimeoutError.new(
              'Workflow execution timed out',
              type: Api::Enums::V1::TimeoutType::TIMEOUT_TYPE_START_TO_CLOSE,
              last_heartbeat_details: []
            )
          when :EVENT_TYPE_WORKFLOW_EXECUTION_CONTINUED_AS_NEW
            attrs = event.workflow_execution_continued_as_new_event_attributes
            hist_run_id = attrs.new_execution_run_id
            next if follow_runs && hist_run_id && !hist_run_id.empty?
            # TODO: Use more specific error and decode failure
            raise Error::WorkflowContinuedAsNewError.new(new_run_id: attrs.new_execution_run_id)
          else
            raise Error, "Unknown close event type: #{event.event_type}"
          end
        end
      end

      def signal(signal, *args, rpc_options: nil)

      Other tags:
        Note: - Handles created as a result of {Client.start_workflow} will signal the latest workflow with the same

      Raises:
      • (Error::RPCError) - RPC error from call.

      Parameters:
      • rpc_options (RPCOptions, nil) -- Advanced RPC options.
      • args (Array) -- Signal arguments.
      • signal (Workflow::Definition::Signal, Symbol, String) -- Signal definition or name.
      • def signal(signal, *args, rpc_options: nil)
          @client._impl.signal_workflow(Interceptor::SignalWorkflowInput.new(
                                          workflow_id: id,
                                          run_id:,
                                          signal:,
                                          args:,
                                          headers: {},
                                          rpc_options:
                                        ))
        end

        def start_update(

        Other tags:
          Note: - Handles created as a result of {Client.start_workflow} will send updates the latest workflow with the same

        Raises:
        • (Error::RPCError) - RPC error from call.
        • (Error::WorkflowUpdateRPCTimeoutOrCanceledError) - This update call timed out or was canceled. This doesn't

        Returns:
        • (WorkflowUpdateHandle) - The update handle.

        Parameters:
        • rpc_options (RPCOptions, nil) -- Advanced RPC options.
        • id (String) -- ID of the update.
        • wait_for_stage (WorkflowUpdateWaitStage) -- Required stage to wait until returning. ADMITTED is not
        • args (Array) -- Update arguments.
        • update (Workflow::Definition::Update, Symbol, String) -- Update definition or name.
        • def start_update(
            update,
            *args,
            wait_for_stage:,
            id: SecureRandom.uuid,
            rpc_options: nil
          )
            @client._impl.start_workflow_update(Interceptor::StartWorkflowUpdateInput.new(
                                                  workflow_id: self.id,
                                                  run_id:,
                                                  update_id: id,
                                                  update:,
                                                  args:,
                                                  wait_for_stage:,
                                                  headers: {},
                                                  rpc_options:
                                                ))
          end

          def terminate(reason = nil, details: [], rpc_options: nil)

          Other tags:
            Note: - Handles created as a result of signal with start will terminate the latest workflow with the same workflow

          Raises:
          • (Error::RPCError) - RPC error from call.

          Parameters:
          • rpc_options (RPCOptions, nil) -- Advanced RPC options.
          • details (Array) -- Details to store on the termination.
          • reason (String, nil) -- Reason for the termination.
          • def terminate(reason = nil, details: [], rpc_options: nil)
              @client._impl.terminate_workflow(Interceptor::TerminateWorkflowInput.new(
                                                 workflow_id: id,
                                                 run_id:,
                                                 first_execution_run_id:,
                                                 reason:,
                                                 details:,
                                                 rpc_options:
                                               ))
            end

            def update_handle(id, specific_run_id: run_id)

            Returns:
            • (WorkflowUpdateHandle) - The update handle.

            Parameters:
            • specific_run_id (String, nil) -- Workflow run ID to get update handle for. Default is the {run_id}. Most
            • id (String) -- ID of the update.
            def update_handle(id, specific_run_id: run_id)
              WorkflowUpdateHandle.new(
                client: @client,
                id:,
                workflow_id: self.id,
                workflow_run_id: specific_run_id,
                known_outcome: nil
              )
            end