3
3
4
4
module Temporal
5
5
class Client
6
+ # Handle for interacting with a workflow.
7
+ #
8
+ # This is usually created via {Temporal::Client#workflow_handle} or returned
9
+ # from {Temporal::Client#start_workflow}.
6
10
class WorkflowHandle
7
- attr_reader :id , :run_id , :result_run_id , :first_execution_run_id
11
+ # @return [String] ID for the workflow.
12
+ attr_reader :id
13
+
14
+ # Run ID used for {#signal} and {#query} calls if present to ensure the query or signal happen
15
+ # on this exact run.
16
+ #
17
+ # This is only set on handles created via {Temporal::Client#workflow_handle} with a `run_id`
18
+ # parameter. {Temporal::Client#start_workflow} does not set this value.
19
+ #
20
+ # This cannot be mutated. If a different run ID is needed, {Temporal::Client#workflow_handle}
21
+ # must be used instead.
22
+ #
23
+ # @return [String]
24
+ attr_reader :run_id
25
+
26
+ # Run ID used for {#result} calls if present to ensure result is for a workflow starting from
27
+ # this run.
28
+ #
29
+ # When this handle is created via {Temporal::Client#workflow_handle}, this is the same as
30
+ # `:run_id`. When this handle is created via {Temporal::Client#start_workflow}, this value
31
+ # will be the resulting run ID.
32
+ #
33
+ # This cannot be mutated. If a different run ID is needed, {Temporal::Client#workflow_handle}
34
+ # must be used instead.
35
+ #
36
+ # @return [String]
37
+ attr_reader :result_run_id
38
+
39
+ # Run ID used for {#cancel} and {#terminate} calls if present to ensure the cancel and
40
+ # terminate happen for a workflow ID started with this run ID.
41
+ #
42
+ # This can be set when using {Temporal::Client#workflow_handle}. When
43
+ # {Temporal::Client#start_workflow} is called without a start signal, this is set to the
44
+ # resulting run.
45
+ #
46
+ # This cannot be mutated. If a different first execution run ID is needed,
47
+ # {Temporal::Client#workflow_handle} must be used instead.
48
+ #
49
+ # @return [String]
50
+ attr_reader :first_execution_run_id
8
51
9
52
def initialize ( client_impl , id , run_id : nil , result_run_id : nil , first_execution_run_id : nil )
10
53
@client_impl = client_impl
@@ -14,10 +57,43 @@ def initialize(client_impl, id, run_id: nil, result_run_id: nil, first_execution
14
57
@first_execution_run_id = first_execution_run_id
15
58
end
16
59
60
+ # Wait for result of the workflow.
61
+ #
62
+ # This will use {#result_run_id} if present to base the result on. To use another run ID,
63
+ # a new handle must be created via {Temporal::Client#workflow_handle}.
64
+ #
65
+ # @param follow_runs [Bool] If true (default), workflow runs will be continually fetched,
66
+ # until the most recent one is found. If false, the first result is used.
67
+ # @param rpc_metadata [Hash<String, String>] Headers used on the RPC call.
68
+ # Keys here override client-level RPC metadata keys.
69
+ # @param rpc_timeout [Integer] Optional RPC deadline to set for each RPC call. Note, this is
70
+ # the timeout for each history RPC call not this overall function.
71
+ #
72
+ # @return [any] Result of the workflow after being converted by the data converter.
73
+ #
74
+ # @raise [Temporal::Error::WorkflowFailure] Workflow failed, was cancelled, was terminated, or
75
+ # timed out. Use the {Temporal::Error::WorkflowFailure#cause} to see the underlying reason.
76
+ # @raise [StandardError] Other possible failures during result fetching.
17
77
def result ( follow_runs : true , rpc_metadata : { } , rpc_timeout : nil )
18
78
client_impl . await_workflow_result ( id , result_run_id , follow_runs , rpc_metadata , rpc_timeout )
19
79
end
20
80
81
+ # Get workflow details.
82
+ #
83
+ # This will get details for {#run_id} if present. To use a different run ID, create a new
84
+ # handle with via {Temporal::Client#workflow_handle}.
85
+ #
86
+ # @note Handles created as a result of {Temporal::Client#start_workflow} will describe the
87
+ # latest workflow with the same workflow ID even if it is unrelated to the started workflow.
88
+ #
89
+ # @param rpc_metadata [Hash<String, String>] Headers used on the RPC call.
90
+ # Keys here override client-level RPC metadata keys.
91
+ # @param rpc_timeout [Integer] Optional RPC deadline to set for each RPC call. Note, this is
92
+ # the timeout for each history RPC call not this overall function.
93
+ #
94
+ # @return [Temporal::Workflow::ExecutionInfo] Workflow details.
95
+ #
96
+ # @raise [Temporal::Error::RPCError] Workflow details could not be fetched.
21
97
def describe ( rpc_metadata : { } , rpc_timeout : nil )
22
98
input = Interceptor ::Client ::DescribeWorkflowInput . new (
23
99
id : id ,
@@ -29,6 +105,22 @@ def describe(rpc_metadata: {}, rpc_timeout: nil)
29
105
client_impl . describe_workflow ( input )
30
106
end
31
107
108
+ # Cancel the workflow.
109
+ #
110
+ # This will issue a cancellation for {#run_id} if present. This call will make sure to use the
111
+ # run chain starting from {#first_execution_run_id} if present. To create handles with these
112
+ # values, use {Temporal::Client#workflow_handle}.
113
+ #
114
+ # @note Handles created as a result of {Temporal::Client#start_workflow} with a start signal
115
+ # will cancel the latest workflow with the same workflow ID even if it is unrelated to the
116
+ # started workflow.
117
+ #
118
+ # @param reason [String] A reason for workflow cancellation.
119
+ # @param rpc_metadata [Hash<String, String>] Headers used on the RPC call.
120
+ # Keys here override client-level RPC metadata keys.
121
+ # @param rpc_timeout [Integer] Optional RPC deadline to set for each RPC call.
122
+ #
123
+ # @raise [Temporal::Error::RPCError] Workflow could not be cancelled.
32
124
def cancel ( reason = nil , rpc_metadata : { } , rpc_timeout : nil )
33
125
input = Interceptor ::Client ::CancelWorkflowInput . new (
34
126
id : id ,
@@ -42,6 +134,26 @@ def cancel(reason = nil, rpc_metadata: {}, rpc_timeout: nil)
42
134
client_impl . cancel_workflow ( input )
43
135
end
44
136
137
+ # Query the workflow.
138
+ #
139
+ # This will query for {#run_id} if present. To use a different run ID, create a new handle
140
+ # with via {Temporal::Client#workflow_handle}.
141
+ #
142
+ # @note Handles created as a result of {Temporal::Client#start_workflow} will query the latest
143
+ # workflow with the same workflow ID even if it is unrelated to the started workflow.
144
+ #
145
+ # @param query [String, Symbol] Query function or name on the workflow.
146
+ # @param args [any] Arguments to the query.
147
+ # @param reject_condition [Symbol] Condition for rejecting the query. Refer to
148
+ # {Temporal::Workflow::QueryRejectCondition} for the list of allowed values.
149
+ # @param rpc_metadata [Hash<String, String>] Headers used on the RPC call.
150
+ # Keys here override client-level RPC metadata keys.
151
+ # @param rpc_timeout [Integer] Optional RPC deadline to set for each RPC call.
152
+ #
153
+ # @return [any] Result of the query.
154
+ #
155
+ # @raise [Temporal::Error] A query reject condition was satisfied.
156
+ # @raise [Temporal::Error::RPCError] Workflow details could not be fetched.
45
157
def query (
46
158
query ,
47
159
*args ,
@@ -63,6 +175,21 @@ def query(
63
175
client_impl . query_workflow ( input )
64
176
end
65
177
178
+ # Send a signal to the workflow.
179
+ #
180
+ # This will signal for {#run_id} if present. To use a different run ID, create a new handle
181
+ # with via {Temporal::Client#workflow_handle}.
182
+ #
183
+ # @note Handles created as a result of {Temporal::Client#start_workflow} will signal the
184
+ # latest workflow with the same workflow ID even if it is unrelated to the started workflow.
185
+ #
186
+ # @param signal [String, Symbol] Signal function or name on the workflow.
187
+ # @param args [any] Arguments to the signal.
188
+ # @param rpc_metadata [Hash<String, String>] Headers used on the RPC call.
189
+ # Keys here override client-level RPC metadata keys.
190
+ # @param rpc_timeout [Integer] Optional RPC deadline to set for each RPC call.
191
+ #
192
+ # @return [Temporal::Error::RPCError] Workflow could not be signalled.
66
193
def signal ( signal , *args , rpc_metadata : { } , rpc_timeout : nil )
67
194
input = Interceptor ::Client ::SignalWorkflowInput . new (
68
195
id : id ,
@@ -77,6 +204,23 @@ def signal(signal, *args, rpc_metadata: {}, rpc_timeout: nil)
77
204
client_impl . signal_workflow ( input )
78
205
end
79
206
207
+ # Terminate the workflow.
208
+ #
209
+ # This will issue a termination for {#run_id} if present. This call will make sure to use the
210
+ # run chain starting from {#first_execution_run_id} if present. To create handles with these
211
+ # values, use {Temporal::Client#workflow_handle}.
212
+
213
+ # @note Handles created as a result of {Temporal::Client#start_workflow} with a start signal
214
+ # will terminate the latest workflow with the same workflow ID even if it is unrelated to
215
+ # the started workflow.
216
+ #
217
+ # @param reason [String] A reason for workflow termination.
218
+ # @param args [any] Details to store on the termination.
219
+ # @param rpc_metadata [Hash<String, String>] Headers used on the RPC call.
220
+ # Keys here override client-level RPC metadata keys.
221
+ # @param rpc_timeout [Integer] Optional RPC deadline to set for each RPC call.
222
+ #
223
+ # @raise [Temporal::Error::RPCError] Workflow could not be terminated.
80
224
def terminate ( reason = nil , args = nil , rpc_metadata : { } , rpc_timeout : nil )
81
225
input = Interceptor ::Client ::TerminateWorkflowInput . new (
82
226
id : id ,
0 commit comments