clara-temporalio 0.4.3-x86_64-linux

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +2 -0
  3. data/Gemfile +27 -0
  4. data/Rakefile +101 -0
  5. data/lib/temporalio/activity/cancellation_details.rb +58 -0
  6. data/lib/temporalio/activity/complete_async_error.rb +11 -0
  7. data/lib/temporalio/activity/context.rb +131 -0
  8. data/lib/temporalio/activity/definition.rb +197 -0
  9. data/lib/temporalio/activity/info.rb +70 -0
  10. data/lib/temporalio/activity.rb +14 -0
  11. data/lib/temporalio/api/activity/v1/message.rb +25 -0
  12. data/lib/temporalio/api/batch/v1/message.rb +38 -0
  13. data/lib/temporalio/api/cloud/account/v1/message.rb +28 -0
  14. data/lib/temporalio/api/cloud/cloudservice/v1/request_response.rb +135 -0
  15. data/lib/temporalio/api/cloud/cloudservice/v1/service.rb +25 -0
  16. data/lib/temporalio/api/cloud/cloudservice.rb +3 -0
  17. data/lib/temporalio/api/cloud/identity/v1/message.rb +46 -0
  18. data/lib/temporalio/api/cloud/namespace/v1/message.rb +46 -0
  19. data/lib/temporalio/api/cloud/nexus/v1/message.rb +32 -0
  20. data/lib/temporalio/api/cloud/operation/v1/message.rb +28 -0
  21. data/lib/temporalio/api/cloud/region/v1/message.rb +24 -0
  22. data/lib/temporalio/api/cloud/resource/v1/message.rb +23 -0
  23. data/lib/temporalio/api/cloud/sink/v1/message.rb +24 -0
  24. data/lib/temporalio/api/cloud/usage/v1/message.rb +31 -0
  25. data/lib/temporalio/api/command/v1/message.rb +46 -0
  26. data/lib/temporalio/api/common/v1/grpc_status.rb +23 -0
  27. data/lib/temporalio/api/common/v1/message.rb +49 -0
  28. data/lib/temporalio/api/deployment/v1/message.rb +39 -0
  29. data/lib/temporalio/api/enums/v1/batch_operation.rb +22 -0
  30. data/lib/temporalio/api/enums/v1/command_type.rb +21 -0
  31. data/lib/temporalio/api/enums/v1/common.rb +28 -0
  32. data/lib/temporalio/api/enums/v1/deployment.rb +23 -0
  33. data/lib/temporalio/api/enums/v1/event_type.rb +21 -0
  34. data/lib/temporalio/api/enums/v1/failed_cause.rb +26 -0
  35. data/lib/temporalio/api/enums/v1/namespace.rb +23 -0
  36. data/lib/temporalio/api/enums/v1/nexus.rb +21 -0
  37. data/lib/temporalio/api/enums/v1/query.rb +22 -0
  38. data/lib/temporalio/api/enums/v1/reset.rb +23 -0
  39. data/lib/temporalio/api/enums/v1/schedule.rb +21 -0
  40. data/lib/temporalio/api/enums/v1/task_queue.rb +25 -0
  41. data/lib/temporalio/api/enums/v1/update.rb +22 -0
  42. data/lib/temporalio/api/enums/v1/workflow.rb +31 -0
  43. data/lib/temporalio/api/errordetails/v1/message.rb +44 -0
  44. data/lib/temporalio/api/export/v1/message.rb +24 -0
  45. data/lib/temporalio/api/failure/v1/message.rb +38 -0
  46. data/lib/temporalio/api/filter/v1/message.rb +27 -0
  47. data/lib/temporalio/api/history/v1/message.rb +94 -0
  48. data/lib/temporalio/api/namespace/v1/message.rb +31 -0
  49. data/lib/temporalio/api/nexus/v1/message.rb +41 -0
  50. data/lib/temporalio/api/operatorservice/v1/request_response.rb +49 -0
  51. data/lib/temporalio/api/operatorservice/v1/service.rb +23 -0
  52. data/lib/temporalio/api/operatorservice.rb +3 -0
  53. data/lib/temporalio/api/payload_visitor.rb +1668 -0
  54. data/lib/temporalio/api/protocol/v1/message.rb +23 -0
  55. data/lib/temporalio/api/query/v1/message.rb +28 -0
  56. data/lib/temporalio/api/replication/v1/message.rb +26 -0
  57. data/lib/temporalio/api/rules/v1/message.rb +27 -0
  58. data/lib/temporalio/api/schedule/v1/message.rb +43 -0
  59. data/lib/temporalio/api/sdk/v1/enhanced_stack_trace.rb +25 -0
  60. data/lib/temporalio/api/sdk/v1/task_complete_metadata.rb +21 -0
  61. data/lib/temporalio/api/sdk/v1/user_metadata.rb +23 -0
  62. data/lib/temporalio/api/sdk/v1/workflow_metadata.rb +23 -0
  63. data/lib/temporalio/api/taskqueue/v1/message.rb +48 -0
  64. data/lib/temporalio/api/testservice/v1/request_response.rb +31 -0
  65. data/lib/temporalio/api/testservice/v1/service.rb +23 -0
  66. data/lib/temporalio/api/update/v1/message.rb +33 -0
  67. data/lib/temporalio/api/version/v1/message.rb +26 -0
  68. data/lib/temporalio/api/workflow/v1/message.rb +63 -0
  69. data/lib/temporalio/api/workflowservice/v1/request_response.rb +244 -0
  70. data/lib/temporalio/api/workflowservice/v1/service.rb +23 -0
  71. data/lib/temporalio/api/workflowservice.rb +3 -0
  72. data/lib/temporalio/api.rb +15 -0
  73. data/lib/temporalio/cancellation.rb +170 -0
  74. data/lib/temporalio/client/activity_id_reference.rb +32 -0
  75. data/lib/temporalio/client/async_activity_handle.rb +85 -0
  76. data/lib/temporalio/client/connection/cloud_service.rb +786 -0
  77. data/lib/temporalio/client/connection/operator_service.rb +201 -0
  78. data/lib/temporalio/client/connection/service.rb +42 -0
  79. data/lib/temporalio/client/connection/test_service.rb +111 -0
  80. data/lib/temporalio/client/connection/workflow_service.rb +1326 -0
  81. data/lib/temporalio/client/connection.rb +316 -0
  82. data/lib/temporalio/client/interceptor.rb +457 -0
  83. data/lib/temporalio/client/schedule.rb +991 -0
  84. data/lib/temporalio/client/schedule_handle.rb +126 -0
  85. data/lib/temporalio/client/with_start_workflow_operation.rb +115 -0
  86. data/lib/temporalio/client/workflow_execution.rb +119 -0
  87. data/lib/temporalio/client/workflow_execution_count.rb +36 -0
  88. data/lib/temporalio/client/workflow_execution_status.rb +18 -0
  89. data/lib/temporalio/client/workflow_handle.rb +389 -0
  90. data/lib/temporalio/client/workflow_query_reject_condition.rb +14 -0
  91. data/lib/temporalio/client/workflow_update_handle.rb +65 -0
  92. data/lib/temporalio/client/workflow_update_wait_stage.rb +17 -0
  93. data/lib/temporalio/client.rb +625 -0
  94. data/lib/temporalio/common_enums.rb +55 -0
  95. data/lib/temporalio/contrib/open_telemetry.rb +469 -0
  96. data/lib/temporalio/converters/data_converter.rb +99 -0
  97. data/lib/temporalio/converters/failure_converter.rb +205 -0
  98. data/lib/temporalio/converters/payload_codec.rb +26 -0
  99. data/lib/temporalio/converters/payload_converter/binary_null.rb +34 -0
  100. data/lib/temporalio/converters/payload_converter/binary_plain.rb +35 -0
  101. data/lib/temporalio/converters/payload_converter/binary_protobuf.rb +42 -0
  102. data/lib/temporalio/converters/payload_converter/composite.rb +66 -0
  103. data/lib/temporalio/converters/payload_converter/encoding.rb +35 -0
  104. data/lib/temporalio/converters/payload_converter/json_plain.rb +44 -0
  105. data/lib/temporalio/converters/payload_converter/json_protobuf.rb +41 -0
  106. data/lib/temporalio/converters/payload_converter.rb +71 -0
  107. data/lib/temporalio/converters/raw_value.rb +20 -0
  108. data/lib/temporalio/converters.rb +9 -0
  109. data/lib/temporalio/error/failure.rb +237 -0
  110. data/lib/temporalio/error.rb +156 -0
  111. data/lib/temporalio/internal/bridge/3.2/temporalio_bridge.so +0 -0
  112. data/lib/temporalio/internal/bridge/3.3/temporalio_bridge.so +0 -0
  113. data/lib/temporalio/internal/bridge/3.4/temporalio_bridge.so +0 -0
  114. data/lib/temporalio/internal/bridge/api/activity_result/activity_result.rb +34 -0
  115. data/lib/temporalio/internal/bridge/api/activity_task/activity_task.rb +32 -0
  116. data/lib/temporalio/internal/bridge/api/child_workflow/child_workflow.rb +33 -0
  117. data/lib/temporalio/internal/bridge/api/common/common.rb +27 -0
  118. data/lib/temporalio/internal/bridge/api/core_interface.rb +40 -0
  119. data/lib/temporalio/internal/bridge/api/external_data/external_data.rb +27 -0
  120. data/lib/temporalio/internal/bridge/api/nexus/nexus.rb +34 -0
  121. data/lib/temporalio/internal/bridge/api/workflow_activation/workflow_activation.rb +56 -0
  122. data/lib/temporalio/internal/bridge/api/workflow_commands/workflow_commands.rb +58 -0
  123. data/lib/temporalio/internal/bridge/api/workflow_completion/workflow_completion.rb +31 -0
  124. data/lib/temporalio/internal/bridge/api.rb +3 -0
  125. data/lib/temporalio/internal/bridge/client.rb +95 -0
  126. data/lib/temporalio/internal/bridge/runtime.rb +56 -0
  127. data/lib/temporalio/internal/bridge/testing.rb +69 -0
  128. data/lib/temporalio/internal/bridge/worker.rb +109 -0
  129. data/lib/temporalio/internal/bridge.rb +36 -0
  130. data/lib/temporalio/internal/client/implementation.rb +926 -0
  131. data/lib/temporalio/internal/metric.rb +122 -0
  132. data/lib/temporalio/internal/proto_utils.rb +165 -0
  133. data/lib/temporalio/internal/worker/activity_worker.rb +448 -0
  134. data/lib/temporalio/internal/worker/multi_runner.rb +213 -0
  135. data/lib/temporalio/internal/worker/workflow_instance/child_workflow_handle.rb +54 -0
  136. data/lib/temporalio/internal/worker/workflow_instance/context.rb +391 -0
  137. data/lib/temporalio/internal/worker/workflow_instance/details.rb +49 -0
  138. data/lib/temporalio/internal/worker/workflow_instance/external_workflow_handle.rb +32 -0
  139. data/lib/temporalio/internal/worker/workflow_instance/externally_immutable_hash.rb +22 -0
  140. data/lib/temporalio/internal/worker/workflow_instance/handler_execution.rb +25 -0
  141. data/lib/temporalio/internal/worker/workflow_instance/handler_hash.rb +41 -0
  142. data/lib/temporalio/internal/worker/workflow_instance/illegal_call_tracer.rb +97 -0
  143. data/lib/temporalio/internal/worker/workflow_instance/inbound_implementation.rb +62 -0
  144. data/lib/temporalio/internal/worker/workflow_instance/outbound_implementation.rb +404 -0
  145. data/lib/temporalio/internal/worker/workflow_instance/replay_safe_logger.rb +37 -0
  146. data/lib/temporalio/internal/worker/workflow_instance/replay_safe_metric.rb +40 -0
  147. data/lib/temporalio/internal/worker/workflow_instance/scheduler.rb +183 -0
  148. data/lib/temporalio/internal/worker/workflow_instance.rb +800 -0
  149. data/lib/temporalio/internal/worker/workflow_worker.rb +249 -0
  150. data/lib/temporalio/internal.rb +7 -0
  151. data/lib/temporalio/metric.rb +109 -0
  152. data/lib/temporalio/priority.rb +59 -0
  153. data/lib/temporalio/retry_policy.rb +74 -0
  154. data/lib/temporalio/runtime/metric_buffer.rb +94 -0
  155. data/lib/temporalio/runtime.rb +352 -0
  156. data/lib/temporalio/scoped_logger.rb +96 -0
  157. data/lib/temporalio/search_attributes.rb +356 -0
  158. data/lib/temporalio/testing/activity_environment.rb +175 -0
  159. data/lib/temporalio/testing/workflow_environment.rb +406 -0
  160. data/lib/temporalio/testing.rb +10 -0
  161. data/lib/temporalio/version.rb +5 -0
  162. data/lib/temporalio/versioning_override.rb +55 -0
  163. data/lib/temporalio/worker/activity_executor/fiber.rb +49 -0
  164. data/lib/temporalio/worker/activity_executor/thread_pool.rb +46 -0
  165. data/lib/temporalio/worker/activity_executor.rb +55 -0
  166. data/lib/temporalio/worker/deployment_options.rb +45 -0
  167. data/lib/temporalio/worker/interceptor.rb +367 -0
  168. data/lib/temporalio/worker/poller_behavior.rb +61 -0
  169. data/lib/temporalio/worker/thread_pool.rb +237 -0
  170. data/lib/temporalio/worker/tuner.rb +189 -0
  171. data/lib/temporalio/worker/workflow_executor/thread_pool.rb +236 -0
  172. data/lib/temporalio/worker/workflow_executor.rb +26 -0
  173. data/lib/temporalio/worker/workflow_replayer.rb +349 -0
  174. data/lib/temporalio/worker.rb +633 -0
  175. data/lib/temporalio/worker_deployment_version.rb +67 -0
  176. data/lib/temporalio/workflow/activity_cancellation_type.rb +20 -0
  177. data/lib/temporalio/workflow/child_workflow_cancellation_type.rb +21 -0
  178. data/lib/temporalio/workflow/child_workflow_handle.rb +43 -0
  179. data/lib/temporalio/workflow/definition.rb +680 -0
  180. data/lib/temporalio/workflow/external_workflow_handle.rb +41 -0
  181. data/lib/temporalio/workflow/future.rb +151 -0
  182. data/lib/temporalio/workflow/handler_unfinished_policy.rb +13 -0
  183. data/lib/temporalio/workflow/info.rb +107 -0
  184. data/lib/temporalio/workflow/parent_close_policy.rb +19 -0
  185. data/lib/temporalio/workflow/update_info.rb +20 -0
  186. data/lib/temporalio/workflow.rb +594 -0
  187. data/lib/temporalio/workflow_history.rb +47 -0
  188. data/lib/temporalio.rb +12 -0
  189. data/temporalio.gemspec +31 -0
  190. metadata +267 -0
@@ -0,0 +1,625 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'google/protobuf/well_known_types'
4
+ require 'logger'
5
+ require 'temporalio/api'
6
+ require 'temporalio/client/async_activity_handle'
7
+ require 'temporalio/client/connection'
8
+ require 'temporalio/client/interceptor'
9
+ require 'temporalio/client/schedule'
10
+ require 'temporalio/client/schedule_handle'
11
+ require 'temporalio/client/with_start_workflow_operation'
12
+ require 'temporalio/client/workflow_execution'
13
+ require 'temporalio/client/workflow_execution_count'
14
+ require 'temporalio/client/workflow_handle'
15
+ require 'temporalio/client/workflow_query_reject_condition'
16
+ require 'temporalio/client/workflow_update_handle'
17
+ require 'temporalio/client/workflow_update_wait_stage'
18
+ require 'temporalio/common_enums'
19
+ require 'temporalio/converters'
20
+ require 'temporalio/error'
21
+ require 'temporalio/internal/client/implementation'
22
+ require 'temporalio/priority'
23
+ require 'temporalio/retry_policy'
24
+ require 'temporalio/runtime'
25
+ require 'temporalio/search_attributes'
26
+ require 'temporalio/versioning_override'
27
+ require 'temporalio/workflow/definition'
28
+
29
+ module Temporalio
30
+ # Client for accessing Temporal.
31
+ #
32
+ # Most users will use {connect} to connect a client. The {workflow_service} method provides access to a raw gRPC
33
+ # client. To create another client on the same connection, like for a different namespace, {options} may be used to
34
+ # get the options as a struct which can then be dup'd, altered, and splatted as kwargs to the constructor (e.g.
35
+ # +Client.new(**my_options.to_h)+).
36
+ #
37
+ # Clients are thread-safe and are meant to be reused for the life of the application. They are built to work in both
38
+ # synchronous and asynchronous contexts. Internally they use callbacks based on {::Queue} which means they are
39
+ # Fiber-compatible.
40
+ class Client
41
+ Options = Data.define(
42
+ :connection,
43
+ :namespace,
44
+ :data_converter,
45
+ :interceptors,
46
+ :logger,
47
+ :default_workflow_query_reject_condition
48
+ )
49
+
50
+ # Options as returned from {options} for +**to_h+ splat use in {initialize}. See {initialize} for details.
51
+ class Options; end # rubocop:disable Lint/EmptyClass
52
+
53
+ # Connect to Temporal server. This is a shortcut for +Connection.new+ followed by +Client.new+.
54
+ #
55
+ # @param target_host [String] +host:port+ for the Temporal server. For local development, this is often
56
+ # +localhost:7233+.
57
+ # @param namespace [String] Namespace to use for client calls.
58
+ # @param api_key [String, nil] API key for Temporal. This becomes the +Authorization+ HTTP header with +"Bearer "+
59
+ # prepended. This is only set if RPC metadata doesn't already have an +authorization+ key.
60
+ # @param tls [Boolean, Connection::TLSOptions] If false, do not use TLS. If true, use system default TLS options. If
61
+ # TLS options are present, those TLS options will be used.
62
+ # @param data_converter [Converters::DataConverter] Data converter to use for all data conversions to/from payloads.
63
+ # @param interceptors [Array<Interceptor>] Set of interceptors that are chained together to allow intercepting of
64
+ # client calls. The earlier interceptors wrap the later ones. Any interceptors that also implement worker
65
+ # interceptor will be used as worker interceptors too so they should not be given separately when creating a
66
+ # worker.
67
+ # @param logger [Logger] Logger to use for this client and any workers made from this client. Defaults to stdout
68
+ # with warn level. Callers setting this logger are responsible for closing it.
69
+ # @param default_workflow_query_reject_condition [WorkflowQueryRejectCondition, nil] Default rejection
70
+ # condition for workflow queries if not set during query. See {WorkflowHandle.query} for details on the
71
+ # rejection condition.
72
+ # @param rpc_metadata [Hash<String, String>] Headers to use for all calls to the server. Keys here can be overriden
73
+ # by per-call RPC metadata keys.
74
+ # @param rpc_retry [Connection::RPCRetryOptions] Retry options for direct service calls (when opted in) or all
75
+ # high-level calls made by this client (which all opt-in to retries by default).
76
+ # @param identity [String] Identity for this client.
77
+ # @param keep_alive [Connection::KeepAliveOptions] Keep-alive options for the client connection. Can be set to +nil+
78
+ # to disable.
79
+ # @param http_connect_proxy [Connection::HTTPConnectProxyOptions, nil] Options for HTTP CONNECT proxy.
80
+ # @param runtime [Runtime] Runtime for this client.
81
+ # @param lazy_connect [Boolean] If true, the client will not connect until the first call is attempted or a worker
82
+ # is created with it. Lazy clients cannot be used for workers if they have not performed a connection.
83
+ #
84
+ # @return [Client] Connected client.
85
+ #
86
+ # @see Connection.initialize
87
+ # @see initialize
88
+ def self.connect(
89
+ target_host,
90
+ namespace,
91
+ api_key: nil,
92
+ tls: false,
93
+ data_converter: Converters::DataConverter.default,
94
+ interceptors: [],
95
+ logger: Logger.new($stdout, level: Logger::WARN),
96
+ default_workflow_query_reject_condition: nil,
97
+ rpc_metadata: {},
98
+ rpc_retry: Connection::RPCRetryOptions.new,
99
+ identity: "#{Process.pid}@#{Socket.gethostname}",
100
+ keep_alive: Connection::KeepAliveOptions.new, # Set to nil to disable
101
+ http_connect_proxy: nil,
102
+ runtime: Runtime.default,
103
+ lazy_connect: false
104
+ )
105
+ Client.new(
106
+ connection: Connection.new(
107
+ target_host:,
108
+ api_key:,
109
+ tls:,
110
+ rpc_metadata:,
111
+ rpc_retry:,
112
+ identity:,
113
+ keep_alive:,
114
+ http_connect_proxy:,
115
+ runtime:,
116
+ lazy_connect:
117
+ ),
118
+ namespace:,
119
+ data_converter:,
120
+ interceptors:,
121
+ logger:,
122
+ default_workflow_query_reject_condition:
123
+ )
124
+ end
125
+
126
+ # @return [Options] Frozen options for this client which has the same attributes as {initialize}.
127
+ attr_reader :options
128
+
129
+ # Create a client from an existing connection. Most users will prefer {connect} instead. Parameters here match
130
+ # {Options} returned from {options} by intention so options can be dup'd, altered, and splatted to create a new
131
+ # client.
132
+ #
133
+ # @param connection [Connection] Existing connection to create a client from.
134
+ # @param namespace [String] Namespace to use for client calls.
135
+ # @param data_converter [Converters::DataConverter] Data converter to use for all data conversions to/from payloads.
136
+ # @param interceptors [Array<Interceptor>] Set of interceptors that are chained together to allow intercepting of
137
+ # client calls. The earlier interceptors wrap the later ones. Any interceptors that also implement worker
138
+ # interceptor will be used as worker interceptors too so they should not be given separately when creating a
139
+ # worker.
140
+ # @param logger [Logger] Logger to use for this client and any workers made from this client. Defaults to stdout
141
+ # with warn level. Callers setting this logger are responsible for closing it.
142
+ # @param default_workflow_query_reject_condition [WorkflowQueryRejectCondition, nil] Default rejection condition for
143
+ # workflow queries if not set during query. See {WorkflowHandle.query} for details on the rejection condition.
144
+ #
145
+ # @see connect
146
+ def initialize(
147
+ connection:,
148
+ namespace:,
149
+ data_converter: DataConverter.default,
150
+ interceptors: [],
151
+ logger: Logger.new($stdout, level: Logger::WARN),
152
+ default_workflow_query_reject_condition: nil
153
+ )
154
+ @options = Options.new(
155
+ connection:,
156
+ namespace:,
157
+ data_converter:,
158
+ interceptors:,
159
+ logger:,
160
+ default_workflow_query_reject_condition:
161
+ ).freeze
162
+ # Initialize interceptors
163
+ @impl = interceptors.reverse_each.reduce(Internal::Client::Implementation.new(self)) do |acc, int| # steep:ignore
164
+ int.intercept_client(acc)
165
+ end
166
+ end
167
+
168
+ # @return [Connection] Underlying connection for this client.
169
+ def connection
170
+ @options.connection
171
+ end
172
+
173
+ # @return [String] Namespace used in calls by this client.
174
+ def namespace
175
+ @options.namespace
176
+ end
177
+
178
+ # @return [DataConverter] Data converter used by this client.
179
+ def data_converter
180
+ @options.data_converter
181
+ end
182
+
183
+ # @return [Connection::WorkflowService] Raw gRPC workflow service.
184
+ def workflow_service
185
+ connection.workflow_service
186
+ end
187
+
188
+ # @return [Connection::OperatorService] Raw gRPC operator service.
189
+ def operator_service
190
+ connection.operator_service
191
+ end
192
+
193
+ # Start a workflow and return its handle.
194
+ #
195
+ # @param workflow [Class<Workflow::Definition>, String, Symbol] Workflow definition class or workflow name.
196
+ # @param args [Array<Object>] Arguments to the workflow.
197
+ # @param id [String] Unique identifier for the workflow execution.
198
+ # @param task_queue [String] Task queue to run the workflow on.
199
+ # @param static_summary [String, nil] Fixed single-line summary for this workflow execution that may appear in
200
+ # CLI/UI. This can be in single-line Temporal markdown format. This is currently experimental.
201
+ # @param static_details [String, nil] Fixed details for this workflow execution that may appear in CLI/UI. This can
202
+ # be in Temporal markdown format and can be multiple lines. This is a fixed value on the workflow that cannot be
203
+ # updated. For details that can be updated, use {Workflow.current_details=} within the workflow. This is currently
204
+ # experimental.
205
+ # @param execution_timeout [Float, nil] Total workflow execution timeout in seconds including retries and continue
206
+ # as new.
207
+ # @param run_timeout [Float, nil] Timeout of a single workflow run in seconds.
208
+ # @param task_timeout [Float, nil] Timeout of a single workflow task in seconds.
209
+ # @param id_reuse_policy [WorkflowIDReusePolicy] How already-existing IDs are treated.
210
+ # @param id_conflict_policy [WorkflowIDConflictPolicy] How already-running workflows of the same ID are treated.
211
+ # Default is unspecified which effectively means fail the start attempt. This cannot be set if `id_reuse_policy`
212
+ # is set to terminate if running.
213
+ # @param retry_policy [RetryPolicy, nil] Retry policy for the workflow.
214
+ # @param cron_schedule [String, nil] Cron schedule. Users should use schedules instead of this.
215
+ # @param memo [Hash{String, Symbol => Object}, nil] Memo for the workflow.
216
+ # @param search_attributes [SearchAttributes, nil] Search attributes for the workflow.
217
+ # @param start_delay [Float, nil] Amount of time in seconds to wait before starting the workflow. This does not work
218
+ # with `cron_schedule`.
219
+ # @param request_eager_start [Boolean] Potentially reduce the latency to start this workflow by encouraging the
220
+ # server to start it on a local worker running with this same client. This is currently experimental.
221
+ # @param versioning_override [VersioningOverride, nil] Override the version of the workflow.
222
+ # This is currently experimental.
223
+ # @param priority [Priority] Priority of the workflow. This is currently experimental.
224
+ # @param rpc_options [RPCOptions, nil] Advanced RPC options.
225
+ #
226
+ # @return [WorkflowHandle] A workflow handle to the started workflow.
227
+ # @raise [Error::WorkflowAlreadyStartedError] Workflow already exists.
228
+ # @raise [Error::RPCError] RPC error from call.
229
+ def start_workflow(
230
+ workflow,
231
+ *args,
232
+ id:,
233
+ task_queue:,
234
+ static_summary: nil,
235
+ static_details: nil,
236
+ execution_timeout: nil,
237
+ run_timeout: nil,
238
+ task_timeout: nil,
239
+ id_reuse_policy: WorkflowIDReusePolicy::ALLOW_DUPLICATE,
240
+ id_conflict_policy: WorkflowIDConflictPolicy::UNSPECIFIED,
241
+ retry_policy: nil,
242
+ cron_schedule: nil,
243
+ memo: nil,
244
+ search_attributes: nil,
245
+ start_delay: nil,
246
+ request_eager_start: false,
247
+ versioning_override: nil,
248
+ priority: Priority.default,
249
+ rpc_options: nil
250
+ )
251
+ @impl.start_workflow(Interceptor::StartWorkflowInput.new(
252
+ workflow: Workflow::Definition._workflow_type_from_workflow_parameter(workflow),
253
+ args:,
254
+ workflow_id: id,
255
+ task_queue:,
256
+ static_summary:,
257
+ static_details:,
258
+ execution_timeout:,
259
+ run_timeout:,
260
+ task_timeout:,
261
+ id_reuse_policy:,
262
+ id_conflict_policy:,
263
+ retry_policy:,
264
+ cron_schedule:,
265
+ memo:,
266
+ search_attributes:,
267
+ start_delay:,
268
+ request_eager_start:,
269
+ headers: {},
270
+ versioning_override:,
271
+ priority:,
272
+ rpc_options:
273
+ ))
274
+ end
275
+
276
+ # Start a workflow and wait for its result. This is a shortcut for {start_workflow} + {WorkflowHandle.result}.
277
+ #
278
+ # @param workflow [Class<Workflow::Definition>, Symbol, String] Workflow definition class or workflow name.
279
+ # @param args [Array<Object>] Arguments to the workflow.
280
+ # @param id [String] Unique identifier for the workflow execution.
281
+ # @param task_queue [String] Task queue to run the workflow on.
282
+ # @param static_summary [String, nil] Fixed single-line summary for this workflow execution that may appear in
283
+ # CLI/UI. This can be in single-line Temporal markdown format. This is currently experimental.
284
+ # @param static_details [String, nil] Fixed details for this workflow execution that may appear in CLI/UI. This can
285
+ # be in Temporal markdown format and can be multiple lines. This is a fixed value on the workflow that cannot be
286
+ # updated. For details that can be updated, use {Workflow.current_details=} within the workflow. This is currently
287
+ # experimental.
288
+ # @param execution_timeout [Float, nil] Total workflow execution timeout in seconds including retries and continue
289
+ # as new.
290
+ # @param run_timeout [Float, nil] Timeout of a single workflow run in seconds.
291
+ # @param task_timeout [Float, nil] Timeout of a single workflow task in seconds.
292
+ # @param id_reuse_policy [WorkflowIDReusePolicy] How already-existing IDs are treated.
293
+ # @param id_conflict_policy [WorkflowIDConflictPolicy] How already-running workflows of the same ID are treated.
294
+ # Default is unspecified which effectively means fail the start attempt. This cannot be set if `id_reuse_policy`
295
+ # is set to terminate if running.
296
+ # @param retry_policy [RetryPolicy, nil] Retry policy for the workflow.
297
+ # @param cron_schedule [String, nil] Cron schedule. Users should use schedules instead of this.
298
+ # @param memo [Hash{String, Symbol => Object}, nil] Memo for the workflow.
299
+ # @param search_attributes [SearchAttributes, nil] Search attributes for the workflow.
300
+ # @param start_delay [Float, nil] Amount of time in seconds to wait before starting the workflow. This does not work
301
+ # with `cron_schedule`.
302
+ # @param request_eager_start [Boolean] Potentially reduce the latency to start this workflow by encouraging the
303
+ # server to start it on a local worker running with this same client. This is currently experimental.
304
+ # @param versioning_override [VersioningOverride, nil] Override the version of the workflow.
305
+ # This is currently experimental.
306
+ # @param priority [Priority] Priority for the workflow. This is currently experimental.
307
+ # @param rpc_options [RPCOptions, nil] Advanced RPC options.
308
+ #
309
+ # @return [Object] Successful result of the workflow.
310
+ # @raise [Error::WorkflowAlreadyStartedError] Workflow already exists.
311
+ # @raise [Error::WorkflowFailedError] Workflow failed with +cause+ as the cause.
312
+ # @raise [Error::RPCError] RPC error from call.
313
+ def execute_workflow(
314
+ workflow,
315
+ *args,
316
+ id:,
317
+ task_queue:,
318
+ static_summary: nil,
319
+ static_details: nil,
320
+ execution_timeout: nil,
321
+ run_timeout: nil,
322
+ task_timeout: nil,
323
+ id_reuse_policy: WorkflowIDReusePolicy::ALLOW_DUPLICATE,
324
+ id_conflict_policy: WorkflowIDConflictPolicy::UNSPECIFIED,
325
+ retry_policy: nil,
326
+ cron_schedule: nil,
327
+ memo: nil,
328
+ search_attributes: nil,
329
+ start_delay: nil,
330
+ request_eager_start: false,
331
+ versioning_override: nil,
332
+ priority: Priority.default,
333
+ follow_runs: true,
334
+ rpc_options: nil
335
+ )
336
+ handle = start_workflow(
337
+ workflow,
338
+ *args,
339
+ id:,
340
+ task_queue:,
341
+ static_summary:,
342
+ static_details:,
343
+ execution_timeout:,
344
+ run_timeout:,
345
+ task_timeout:,
346
+ id_reuse_policy:,
347
+ id_conflict_policy:,
348
+ retry_policy:,
349
+ cron_schedule:,
350
+ memo:,
351
+ search_attributes:,
352
+ start_delay:,
353
+ request_eager_start:,
354
+ versioning_override:,
355
+ priority:,
356
+ rpc_options:
357
+ )
358
+ follow_runs ? handle.result : handle
359
+ end
360
+
361
+ # Get a workflow handle to an existing workflow by its ID.
362
+ #
363
+ # @param workflow_id [String] Workflow ID to get a handle to.
364
+ # @param run_id [String, nil] Run ID that will be used for all calls. Many choose to leave this unset which ensures
365
+ # interactions occur on the latest of the workflow ID.
366
+ # @param first_execution_run_id [String, nil] First execution run ID used for some calls like cancellation and
367
+ # termination to ensure the affected workflow is only within the same chain as this given run ID.
368
+ #
369
+ # @return [WorkflowHandle] The workflow handle.
370
+ def workflow_handle(
371
+ workflow_id,
372
+ run_id: nil,
373
+ first_execution_run_id: nil
374
+ )
375
+ WorkflowHandle.new(client: self, id: workflow_id, run_id:, result_run_id: run_id, first_execution_run_id:)
376
+ end
377
+
378
+ # Start an update, possibly starting the workflow at the same time if it doesn't exist (depending upon ID conflict
379
+ # policy). Note that in some cases this may fail but the workflow will still be started, and the handle can then be
380
+ # retrieved on the start workflow operation.
381
+ #
382
+ # @param update [Workflow::Definition::Update, Symbol, String] Update definition or name.
383
+ # @param args [Array<Object>] Update arguments.
384
+ # @param start_workflow_operation [WithStartWorkflowOperation] Required with-start workflow operation. This must
385
+ # have an `id_conflict_policy` set.
386
+ # @param wait_for_stage [WorkflowUpdateWaitStage] Required stage to wait until returning. ADMITTED is not
387
+ # currently supported. See https://docs.temporal.io/workflows#update for more details.
388
+ # @param id [String] ID of the update.
389
+ # @param rpc_options [RPCOptions, nil] Advanced RPC options.
390
+ #
391
+ # @return [WorkflowUpdateHandle] The update handle.
392
+ # @raise [Error::WorkflowAlreadyStartedError] Workflow already exists and conflict/reuse policy does not allow.
393
+ # @raise [Error::WorkflowUpdateRPCTimeoutOrCanceledError] This update call timed out or was canceled. This doesn't
394
+ # mean the update itself was timed out or canceled, and this doesn't mean the workflow did not start.
395
+ # @raise [Error::RPCError] RPC error from call.
396
+ def start_update_with_start_workflow(
397
+ update,
398
+ *args,
399
+ start_workflow_operation:,
400
+ wait_for_stage:,
401
+ id: SecureRandom.uuid,
402
+ rpc_options: nil
403
+ )
404
+ @impl.start_update_with_start_workflow(
405
+ Interceptor::StartUpdateWithStartWorkflowInput.new(
406
+ update_id: id,
407
+ update: Workflow::Definition::Update._name_from_parameter(update),
408
+ args:,
409
+ wait_for_stage:,
410
+ start_workflow_operation:,
411
+ headers: {},
412
+ rpc_options:
413
+ )
414
+ )
415
+ end
416
+
417
+ # Start an update, possibly starting the workflow at the same time if it doesn't exist (depending upon ID conflict
418
+ # policy), and wait for update result. This is a shortcut for {start_update_with_start_workflow} +
419
+ # {WorkflowUpdateHandle.result}.
420
+ #
421
+ # @param update [Workflow::Definition::Update, Symbol, String] Update definition or name.
422
+ # @param args [Array<Object>] Update arguments.
423
+ # @param start_workflow_operation [WithStartWorkflowOperation] Required with-start workflow operation. This must
424
+ # have an `id_conflict_policy` set.
425
+ # @param id [String] ID of the update.
426
+ # @param rpc_options [RPCOptions, nil] Advanced RPC options.
427
+ #
428
+ # @return [Object] Successful update result.
429
+ # @raise [Error::WorkflowUpdateFailedError] If the update failed.
430
+ # @raise [Error::WorkflowAlreadyStartedError] Workflow already exists and conflict/reuse policy does not allow.
431
+ # @raise [Error::WorkflowUpdateRPCTimeoutOrCanceledError] This update call timed out or was canceled. This doesn't
432
+ # mean the update itself was timed out or canceled, and this doesn't mean the workflow did not start.
433
+ # @raise [Error::RPCError] RPC error from call.
434
+ def execute_update_with_start_workflow(
435
+ update,
436
+ *args,
437
+ start_workflow_operation:,
438
+ id: SecureRandom.uuid,
439
+ rpc_options: nil
440
+ )
441
+ start_update_with_start_workflow(
442
+ update,
443
+ *args,
444
+ start_workflow_operation:,
445
+ wait_for_stage: WorkflowUpdateWaitStage::COMPLETED,
446
+ id:,
447
+ rpc_options:
448
+ ).result
449
+ end
450
+
451
+ # Send a signal, possibly starting the workflow at the same time if it doesn't exist.
452
+ #
453
+ # @param signal [Workflow::Definition::Signal, Symbol, String] Signal definition or name.
454
+ # @param args [Array<Object>] Signal arguments.
455
+ # @param start_workflow_operation [WithStartWorkflowOperation] Required with-start workflow operation. This may not
456
+ # support all `id_conflict_policy` options.
457
+ # @param rpc_options [RPCOptions, nil] Advanced RPC options.
458
+ #
459
+ # @return [WorkflowHandle] A workflow handle to the workflow.
460
+ # @raise [Error::WorkflowAlreadyStartedError] Workflow already exists and conflict/reuse policy does not allow.
461
+ # @raise [Error::RPCError] RPC error from call.
462
+ def signal_with_start_workflow(
463
+ signal,
464
+ *args,
465
+ start_workflow_operation:,
466
+ rpc_options: nil
467
+ )
468
+ @impl.signal_with_start_workflow(
469
+ Interceptor::SignalWithStartWorkflowInput.new(
470
+ signal: Workflow::Definition::Signal._name_from_parameter(signal),
471
+ args:,
472
+ start_workflow_operation:,
473
+ rpc_options:
474
+ )
475
+ )
476
+ end
477
+
478
+ # List workflows.
479
+ #
480
+ # @param query [String, nil] A Temporal visibility list filter.
481
+ # @param rpc_options [RPCOptions, nil] Advanced RPC options.
482
+ #
483
+ # @return [Enumerator<WorkflowExecution>] Enumerable workflow executions.
484
+ #
485
+ # @raise [Error::RPCError] RPC error from call.
486
+ #
487
+ # @see https://docs.temporal.io/visibility
488
+ def list_workflows(query = nil, rpc_options: nil)
489
+ @impl.list_workflows(Interceptor::ListWorkflowsInput.new(query:, rpc_options:))
490
+ end
491
+
492
+ # Count workflows.
493
+ #
494
+ # @param query [String, nil] A Temporal visibility list filter.
495
+ # @param rpc_options [RPCOptions, nil] Advanced RPC options.
496
+ #
497
+ # @return [WorkflowExecutionCount] Count of workflows.
498
+ #
499
+ # @raise [Error::RPCError] RPC error from call.
500
+ #
501
+ # @see https://docs.temporal.io/visibility
502
+ def count_workflows(query = nil, rpc_options: nil)
503
+ @impl.count_workflows(Interceptor::CountWorkflowsInput.new(query:, rpc_options:))
504
+ end
505
+
506
+ # Create a schedule and return its handle.
507
+ #
508
+ # @param id [String] Unique identifier of the schedule.
509
+ # @param schedule [Schedule] Schedule to create.
510
+ # @param trigger_immediately [Boolean] If true, trigger one action immediately when creating the schedule.
511
+ # @param backfills [Array<Schedule::Backfill>] Set of time periods to take actions on as if that time passed right
512
+ # now.
513
+ # @param memo [Hash<String, Object>, nil] Memo for the schedule. Memo for a scheduled workflow is part of the
514
+ # schedule action.
515
+ # @param search_attributes [SearchAttributes, nil] Search attributes for the schedule. Search attributes for a
516
+ # scheduled workflow are part of the scheduled action.
517
+ # @param rpc_options [RPCOptions, nil] Advanced RPC options.
518
+ #
519
+ # @return [ScheduleHandle] A handle to the created schedule.
520
+ # @raise [Error::ScheduleAlreadyRunningError] If a schedule with this ID is already running.
521
+ # @raise [Error::RPCError] RPC error from call.
522
+ def create_schedule(
523
+ id,
524
+ schedule,
525
+ trigger_immediately: false,
526
+ backfills: [],
527
+ memo: nil,
528
+ search_attributes: nil,
529
+ rpc_options: nil
530
+ )
531
+ @impl.create_schedule(Interceptor::CreateScheduleInput.new(
532
+ id:,
533
+ schedule:,
534
+ trigger_immediately:,
535
+ backfills:,
536
+ memo:,
537
+ search_attributes:,
538
+ rpc_options:
539
+ ))
540
+ end
541
+
542
+ # Get a schedule handle to an existing schedule for the given ID.
543
+ #
544
+ # @param id [String] Schedule ID to get a handle to.
545
+ # @return [ScheduleHandle] The schedule handle.
546
+ def schedule_handle(id)
547
+ ScheduleHandle.new(client: self, id:)
548
+ end
549
+
550
+ # List schedules.
551
+ #
552
+ # Note, this list is eventually consistent. Therefore if a schedule is added or deleted, it may not be available in
553
+ # the list immediately.
554
+ #
555
+ # @param query [String] A Temporal visibility list filter.
556
+ # @param rpc_options [RPCOptions, nil] Advanced RPC options.
557
+ #
558
+ # @return [Enumerator<Schedule::List::Description>] Enumerable schedules.
559
+ #
560
+ # @raise [Error::RPCError] RPC error from call.
561
+ #
562
+ # @see https://docs.temporal.io/visibility
563
+ def list_schedules(query = nil, rpc_options: nil)
564
+ @impl.list_schedules(Interceptor::ListSchedulesInput.new(query:, rpc_options:))
565
+ end
566
+
567
+ # Get an async activity handle.
568
+ #
569
+ # @param task_token_or_id_reference [String, ActivityIDReference] Task token string or activity ID reference.
570
+ # @return [AsyncActivityHandle]
571
+ def async_activity_handle(task_token_or_id_reference)
572
+ if task_token_or_id_reference.is_a?(ActivityIDReference)
573
+ AsyncActivityHandle.new(client: self, task_token: nil, id_reference: task_token_or_id_reference)
574
+ elsif task_token_or_id_reference.is_a?(String)
575
+ AsyncActivityHandle.new(client: self, task_token: task_token_or_id_reference, id_reference: nil)
576
+ else
577
+ raise ArgumentError, 'Must be a string task token or an ActivityIDReference'
578
+ end
579
+ end
580
+
581
+ # @!visibility private
582
+ def _impl
583
+ @impl
584
+ end
585
+
586
+ # Set of RPC options for RPC calls.
587
+ class RPCOptions
588
+ # @return [Hash<String, String>, nil] Headers to include on the RPC call.
589
+ attr_accessor :metadata
590
+
591
+ # @return [Float, nil] Number of seconds before timeout of the RPC call.
592
+ attr_accessor :timeout
593
+
594
+ # @return [Cancellation, nil] Cancellation to use to potentially cancel the call. If canceled, the RPC will return
595
+ # {Error::CanceledError}.
596
+ attr_accessor :cancellation
597
+
598
+ # @return [Boolean, nil] Whether to override the default retry option which decides whether to retry calls
599
+ # implicitly when known transient error codes are reached. By default when this is nil, high-level calls retry
600
+ # known transient error codes and low-level/direct calls do not.
601
+ attr_accessor :override_retry
602
+
603
+ # Create RPC options.
604
+ #
605
+ # @param metadata [Hash<String, String>, nil] Headers to include on the RPC call.
606
+ # @param timeout [Float, nil] Number of seconds before timeout of the RPC call.
607
+ # @param cancellation [Cancellation, nil] Cancellation to use to potentially cancel the call. If canceled, the RPC
608
+ # will return {Error::CanceledError}.
609
+ # @param override_retry [Boolean, nil] Whether to override the default retry option which decides whether to retry
610
+ # calls implicitly when known transient error codes are reached. By default when this is nil, high-level calls
611
+ # retry known transient error codes and low-level/direct calls do not.
612
+ def initialize(
613
+ metadata: nil,
614
+ timeout: nil,
615
+ cancellation: nil,
616
+ override_retry: nil
617
+ )
618
+ @metadata = metadata
619
+ @timeout = timeout
620
+ @cancellation = cancellation
621
+ @override_retry = override_retry
622
+ end
623
+ end
624
+ end
625
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'temporalio/api'
4
+
5
+ module Temporalio
6
+ # How already-in-use workflow IDs are handled on start.
7
+ #
8
+ # @see https://docs.temporal.io/workflows#workflow-id-reuse-policy
9
+ module WorkflowIDReusePolicy
10
+ # Allow starting a workflow execution using the same workflow ID.
11
+ ALLOW_DUPLICATE = Api::Enums::V1::WorkflowIdReusePolicy::WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE
12
+ # Allow starting a workflow execution using the same workflow ID, only when the last execution's final state is one
13
+ # of terminated, canceled, timed out, or failed.
14
+ ALLOW_DUPLICATE_FAILED_ONLY =
15
+ Api::Enums::V1::WorkflowIdReusePolicy::WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE_FAILED_ONLY
16
+ # Do not permit re-use of the workflow ID for this workflow. Future start workflow requests could potentially change
17
+ # the policy, allowing re-use of the workflow ID.
18
+ REJECT_DUPLICATE = Api::Enums::V1::WorkflowIdReusePolicy::WORKFLOW_ID_REUSE_POLICY_REJECT_DUPLICATE
19
+ # This option is {WorkflowIDConflictPolicy::TERMINATE_EXISTING} but is here for backwards compatibility. If
20
+ # specified, it acts like {ALLOW_DUPLICATE}, but also the {WorkflowIDConflictPolicy} on the request is treated as
21
+ # {WorkflowIDConflictPolicy::TERMINATE_EXISTING}. If no running workflow, then the behavior is the same as
22
+ # {ALLOW_DUPLICATE}.
23
+ #
24
+ # @deprecated Use {WorkflowIDConflictPolicy::TERMINATE_EXISTING} instead.
25
+ TERMINATE_IF_RUNNING = Api::Enums::V1::WorkflowIdReusePolicy::WORKFLOW_ID_REUSE_POLICY_TERMINATE_IF_RUNNING
26
+ end
27
+
28
+ # How already-running workflows of the same ID are handled on start.
29
+ #
30
+ # @see https://docs.temporal.io/workflows#workflow-id-conflict-policy
31
+ module WorkflowIDConflictPolicy
32
+ # Unset.
33
+ UNSPECIFIED = Api::Enums::V1::WorkflowIdConflictPolicy::WORKFLOW_ID_CONFLICT_POLICY_UNSPECIFIED
34
+ # Don't start a new workflow, instead fail with already-started error.
35
+ FAIL = Api::Enums::V1::WorkflowIdConflictPolicy::WORKFLOW_ID_CONFLICT_POLICY_FAIL
36
+ # Don't start a new workflow, instead return a workflow handle for the running workflow.
37
+ USE_EXISTING = Api::Enums::V1::WorkflowIdConflictPolicy::WORKFLOW_ID_CONFLICT_POLICY_USE_EXISTING
38
+ # Terminate the running workflow before starting a new one.
39
+ TERMINATE_EXISTING = Api::Enums::V1::WorkflowIdConflictPolicy::WORKFLOW_ID_CONFLICT_POLICY_TERMINATE_EXISTING
40
+ end
41
+
42
+ # Specifies when a workflow might move from a worker of one Build Id to another.
43
+ #
44
+ # WARNING: Experimental API.
45
+ module VersioningBehavior
46
+ # Unspecified versioning behavior. By default, workers opting into worker versioning will
47
+ # be required to specify a behavior.
48
+ UNSPECIFIED = Api::Enums::V1::VersioningBehavior::VERSIONING_BEHAVIOR_UNSPECIFIED
49
+ # The workflow will be pinned to the current Build ID unless manually moved.
50
+ PINNED = Api::Enums::V1::VersioningBehavior::VERSIONING_BEHAVIOR_PINNED
51
+ # The workflow will automatically move to the latest version (default Build ID of the task
52
+ # queue) when the next task is dispatched.
53
+ AUTO_UPGRADE = Api::Enums::V1::VersioningBehavior::VERSIONING_BEHAVIOR_AUTO_UPGRADE
54
+ end
55
+ end