Class: Temporalio::Client::ActivityHandle

Inherits:
Object
  • Object
show all
Defined in:
lib/temporalio/client/activity_handle.rb

Overview

Handle for interacting with a standalone activity. Usually created via #activity_handle or #start_activity.

WARNING: Standalone Activities are experimental.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#idString (readonly)

Returns ID for the activity.

Returns:

  • (String)

    ID for the activity.



16
17
18
# File 'lib/temporalio/client/activity_handle.rb', line 16

def id
  @id
end

#result_hintObject? (readonly)

Returns Result hint used when deserializing the activity’s result. May be overridden per #result call.

Returns:

  • (Object, nil)

    Result hint used when deserializing the activity’s result. May be overridden per #result call.



23
24
25
# File 'lib/temporalio/client/activity_handle.rb', line 23

def result_hint
  @result_hint
end

#run_idString? (readonly)

Returns Run ID for this activity execution. When nil, this handle targets the latest run.

Returns:

  • (String, nil)

    Run ID for this activity execution. When nil, this handle targets the latest run.



19
20
21
# File 'lib/temporalio/client/activity_handle.rb', line 19

def run_id
  @run_id
end

Instance Method Details

#cancel(reason = nil, rpc_options: nil) ⇒ Object

Request cancellation of the activity.

Parameters:

  • reason (String, nil) (defaults to: nil)

    Optional cancellation reason recorded on the server.

  • rpc_options (RPCOptions, nil) (defaults to: nil)

    Advanced RPC options.

Raises:



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/temporalio/client/activity_handle.rb', line 77

def cancel(reason = nil, rpc_options: nil)
  @client._impl.cancel_activity(
    Interceptor::CancelActivityInput.new(
      activity_id: id,
      activity_run_id: run_id,
      reason:,
      rpc_options:
    )
  )
  nil
end

#describe(rpc_options: nil) ⇒ ActivityExecution::Description

Describe the activity.

Parameters:

  • rpc_options (RPCOptions, nil) (defaults to: nil)

    Advanced RPC options.

Returns:

Raises:



62
63
64
65
66
67
68
69
70
# File 'lib/temporalio/client/activity_handle.rb', line 62

def describe(rpc_options: nil)
  @client._impl.describe_activity(
    Interceptor::DescribeActivityInput.new(
      activity_id: id,
      activity_run_id: run_id,
      rpc_options:
    )
  )
end

#result(result_hint: nil, rpc_options: nil) ⇒ Object?

Wait for the activity’s outcome (result or failure). Internally long-polls PollActivityExecution and reissues until the activity reaches a terminal state, so this can block indefinitely for long-running activities.

Parameters:

  • result_hint (Object, nil) (defaults to: nil)

    Override the result hint. If nil, uses #result_hint.

  • rpc_options (RPCOptions, nil) (defaults to: nil)

    Advanced RPC options.

Returns:

  • (Object, nil)

    Deserialized activity result.

Raises:



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/temporalio/client/activity_handle.rb', line 44

def result(result_hint: nil, rpc_options: nil)
  hint = result_hint || @result_hint
  outcome = @client._impl.fetch_activity_outcome(
    Interceptor::FetchActivityOutcomeInput.new(
      activity_id: id,
      activity_run_id: run_id,
      rpc_options:
    )
  )
  _process_outcome(outcome, hint)
end

#terminate(reason = nil, rpc_options: nil) ⇒ Object

Terminate the activity (force-close).

Parameters:

  • reason (String, nil) (defaults to: nil)

    Optional termination reason recorded on the activity’s failure outcome.

  • rpc_options (RPCOptions, nil) (defaults to: nil)

    Advanced RPC options.

Raises:



94
95
96
97
98
99
100
101
102
103
104
# File 'lib/temporalio/client/activity_handle.rb', line 94

def terminate(reason = nil, rpc_options: nil)
  @client._impl.terminate_activity(
    Interceptor::TerminateActivityInput.new(
      activity_id: id,
      activity_run_id: run_id,
      reason:,
      rpc_options:
    )
  )
  nil
end