Skip to content

Commit a9238bf

Browse files
authored
[Feature] Add YARD docs to all the public classes (#57)
* Add YARD docs to all the public classes * Suggested fixes
1 parent 73e664b commit a9238bf

File tree

14 files changed

+675
-19
lines changed

14 files changed

+675
-19
lines changed

lib/temporal/client.rb

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,49 @@
99

1010
module Temporal
1111
class Client
12+
# @return [String] Namespace used for client calls.
1213
attr_reader :namespace
1314

14-
# TODO: More argument to follow for converters, codecs, etc
15+
# Create a Temporal client from a connection.
16+
#
17+
# @param connection [Temporal::Connection] A connection to the Temporal server.
18+
# @param namespace [String] Namespace to use for client calls.
19+
# @param interceptors [Array<Temporal::Interceptor::Client>] List of interceptors for
20+
# intercepting client calls. Executed in their original order.
1521
def initialize(connection, namespace, interceptors: [])
1622
@namespace = namespace
1723
data_converter = DataConverter.new
1824
@implementation = Client::Implementation.new(connection, namespace, data_converter, interceptors)
1925
end
2026

27+
# Start a workflow and return its handle.
28+
#
29+
# @param workflow [String] Name of the workflow.
30+
# @param args [any] Arguments to the workflow.
31+
# @param id [String] Unique identifier for the workflow execution.
32+
# @param task_queue [String, Symbol] Task queue to run the workflow on.
33+
# @param execution_timeout [Integer] Total workflow execution timeout including
34+
# retries and continue as new.
35+
# @param run_timeout [Integer] Timeout of a single workflow run.
36+
# @param task_timeout [Integer] Timeout of a single workflow task.
37+
# @param id_reuse_policy [Symbol] How already-existing IDs are treated. Refer to
38+
# {Temporal::Workflow::IDReusePolicy} for the list of allowed values.
39+
# @param retry_policy [Temporal::RetryPolicy] Retry policy for the workflow.
40+
# See {Temporal::RetryPolicy}.
41+
# @param cron_schedule [String] See https://docs.temporal.io/docs/content/what-is-a-temporal-cron-job.
42+
# @param memo [Hash<String, any>] Memo for the workflow.
43+
# @param search_attributes [Hash<String, any>] Search attributes for the workflow.
44+
# @param start_signal [String, Symbol] If present, this signal is sent as signal-with-start
45+
# instead of traditional workflow start.
46+
# @param start_signal_args [Array<any>] Arguments for start_signal if `:start_signal`
47+
# present.
48+
# @param rpc_metadata [Hash<String, String>] Headers used on the RPC call. Keys here override
49+
# client-level RPC metadata keys.
50+
# @param rpc_timeout [Integer] Optional RPC deadline to set for the RPC call.
51+
#
52+
# @return [Temporal::Client::WorkflowHandle] A workflow handle to the started/existing workflow.
53+
#
54+
# @raise [Temporal::Error::RPCError] Workflow could not be started.
2155
def start_workflow( # rubocop:disable Metrics/ParameterLists
2256
workflow,
2357
*args,
@@ -59,6 +93,16 @@ def start_workflow( # rubocop:disable Metrics/ParameterLists
5993
implementation.start_workflow(input)
6094
end
6195

96+
# Get a workflow handle to an existing workflow by its ID.
97+
#
98+
# @param id [String] Workflow ID to get a handle to.
99+
# @param run_id [String, nil] Run ID that will be used for all calls. If omitted, the latest run
100+
# for a given workflow ID will be referenced.
101+
# @param first_execution_run_id [String, nil] A run ID referencing the first workflow execution
102+
# in a chain. Workflows are chained when using continue-as-new, retries (as permitted by the
103+
# retry policy) or cron executions.
104+
#
105+
# @return [Temporal::Client::WorkflowHandle] The workflow handle.
62106
def workflow_handle(id, run_id: nil, first_execution_run_id: nil)
63107
WorkflowHandle.new(
64108
implementation,

lib/temporal/client/workflow_handle.rb

Lines changed: 145 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,51 @@
33

44
module Temporal
55
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}.
610
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
851

952
def initialize(client_impl, id, run_id: nil, result_run_id: nil, first_execution_run_id: nil)
1053
@client_impl = client_impl
@@ -14,10 +57,43 @@ def initialize(client_impl, id, run_id: nil, result_run_id: nil, first_execution
1457
@first_execution_run_id = first_execution_run_id
1558
end
1659

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.
1777
def result(follow_runs: true, rpc_metadata: {}, rpc_timeout: nil)
1878
client_impl.await_workflow_result(id, result_run_id, follow_runs, rpc_metadata, rpc_timeout)
1979
end
2080

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.
2197
def describe(rpc_metadata: {}, rpc_timeout: nil)
2298
input = Interceptor::Client::DescribeWorkflowInput.new(
2399
id: id,
@@ -29,6 +105,22 @@ def describe(rpc_metadata: {}, rpc_timeout: nil)
29105
client_impl.describe_workflow(input)
30106
end
31107

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.
32124
def cancel(reason = nil, rpc_metadata: {}, rpc_timeout: nil)
33125
input = Interceptor::Client::CancelWorkflowInput.new(
34126
id: id,
@@ -42,6 +134,26 @@ def cancel(reason = nil, rpc_metadata: {}, rpc_timeout: nil)
42134
client_impl.cancel_workflow(input)
43135
end
44136

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.
45157
def query(
46158
query,
47159
*args,
@@ -63,6 +175,21 @@ def query(
63175
client_impl.query_workflow(input)
64176
end
65177

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.
66193
def signal(signal, *args, rpc_metadata: {}, rpc_timeout: nil)
67194
input = Interceptor::Client::SignalWorkflowInput.new(
68195
id: id,
@@ -77,6 +204,23 @@ def signal(signal, *args, rpc_metadata: {}, rpc_timeout: nil)
77204
client_impl.signal_workflow(input)
78205
end
79206

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.
80224
def terminate(reason = nil, args = nil, rpc_metadata: {}, rpc_timeout: nil)
81225
input = Interceptor::Client::TerminateWorkflowInput.new(
82226
id: id,

0 commit comments

Comments
 (0)