temporalio 0.2.0-arm64-darwin

Sign up to get free protection for your applications and to get access to all the features.
Files changed (130) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +23 -0
  3. data/Rakefile +387 -0
  4. data/lib/temporalio/activity/complete_async_error.rb +11 -0
  5. data/lib/temporalio/activity/context.rb +107 -0
  6. data/lib/temporalio/activity/definition.rb +77 -0
  7. data/lib/temporalio/activity/info.rb +63 -0
  8. data/lib/temporalio/activity.rb +69 -0
  9. data/lib/temporalio/api/batch/v1/message.rb +31 -0
  10. data/lib/temporalio/api/cloud/cloudservice/v1/request_response.rb +93 -0
  11. data/lib/temporalio/api/cloud/cloudservice/v1/service.rb +25 -0
  12. data/lib/temporalio/api/cloud/cloudservice.rb +3 -0
  13. data/lib/temporalio/api/cloud/identity/v1/message.rb +36 -0
  14. data/lib/temporalio/api/cloud/namespace/v1/message.rb +35 -0
  15. data/lib/temporalio/api/cloud/operation/v1/message.rb +27 -0
  16. data/lib/temporalio/api/cloud/region/v1/message.rb +23 -0
  17. data/lib/temporalio/api/command/v1/message.rb +46 -0
  18. data/lib/temporalio/api/common/v1/grpc_status.rb +23 -0
  19. data/lib/temporalio/api/common/v1/message.rb +41 -0
  20. data/lib/temporalio/api/enums/v1/batch_operation.rb +22 -0
  21. data/lib/temporalio/api/enums/v1/command_type.rb +21 -0
  22. data/lib/temporalio/api/enums/v1/common.rb +26 -0
  23. data/lib/temporalio/api/enums/v1/event_type.rb +21 -0
  24. data/lib/temporalio/api/enums/v1/failed_cause.rb +26 -0
  25. data/lib/temporalio/api/enums/v1/namespace.rb +23 -0
  26. data/lib/temporalio/api/enums/v1/query.rb +22 -0
  27. data/lib/temporalio/api/enums/v1/reset.rb +23 -0
  28. data/lib/temporalio/api/enums/v1/schedule.rb +21 -0
  29. data/lib/temporalio/api/enums/v1/task_queue.rb +25 -0
  30. data/lib/temporalio/api/enums/v1/update.rb +22 -0
  31. data/lib/temporalio/api/enums/v1/workflow.rb +30 -0
  32. data/lib/temporalio/api/errordetails/v1/message.rb +42 -0
  33. data/lib/temporalio/api/export/v1/message.rb +24 -0
  34. data/lib/temporalio/api/failure/v1/message.rb +35 -0
  35. data/lib/temporalio/api/filter/v1/message.rb +27 -0
  36. data/lib/temporalio/api/history/v1/message.rb +90 -0
  37. data/lib/temporalio/api/namespace/v1/message.rb +31 -0
  38. data/lib/temporalio/api/nexus/v1/message.rb +40 -0
  39. data/lib/temporalio/api/operatorservice/v1/request_response.rb +49 -0
  40. data/lib/temporalio/api/operatorservice/v1/service.rb +23 -0
  41. data/lib/temporalio/api/operatorservice.rb +3 -0
  42. data/lib/temporalio/api/protocol/v1/message.rb +23 -0
  43. data/lib/temporalio/api/query/v1/message.rb +27 -0
  44. data/lib/temporalio/api/replication/v1/message.rb +26 -0
  45. data/lib/temporalio/api/schedule/v1/message.rb +42 -0
  46. data/lib/temporalio/api/sdk/v1/enhanced_stack_trace.rb +25 -0
  47. data/lib/temporalio/api/sdk/v1/task_complete_metadata.rb +21 -0
  48. data/lib/temporalio/api/sdk/v1/user_metadata.rb +23 -0
  49. data/lib/temporalio/api/sdk/v1/workflow_metadata.rb +23 -0
  50. data/lib/temporalio/api/taskqueue/v1/message.rb +45 -0
  51. data/lib/temporalio/api/update/v1/message.rb +33 -0
  52. data/lib/temporalio/api/version/v1/message.rb +26 -0
  53. data/lib/temporalio/api/workflow/v1/message.rb +43 -0
  54. data/lib/temporalio/api/workflowservice/v1/request_response.rb +189 -0
  55. data/lib/temporalio/api/workflowservice/v1/service.rb +23 -0
  56. data/lib/temporalio/api/workflowservice.rb +3 -0
  57. data/lib/temporalio/api.rb +13 -0
  58. data/lib/temporalio/cancellation.rb +150 -0
  59. data/lib/temporalio/client/activity_id_reference.rb +32 -0
  60. data/lib/temporalio/client/async_activity_handle.rb +110 -0
  61. data/lib/temporalio/client/connection/cloud_service.rb +648 -0
  62. data/lib/temporalio/client/connection/operator_service.rb +249 -0
  63. data/lib/temporalio/client/connection/service.rb +41 -0
  64. data/lib/temporalio/client/connection/workflow_service.rb +1218 -0
  65. data/lib/temporalio/client/connection.rb +270 -0
  66. data/lib/temporalio/client/interceptor.rb +316 -0
  67. data/lib/temporalio/client/workflow_execution.rb +103 -0
  68. data/lib/temporalio/client/workflow_execution_count.rb +36 -0
  69. data/lib/temporalio/client/workflow_execution_status.rb +18 -0
  70. data/lib/temporalio/client/workflow_handle.rb +446 -0
  71. data/lib/temporalio/client/workflow_query_reject_condition.rb +14 -0
  72. data/lib/temporalio/client/workflow_update_handle.rb +67 -0
  73. data/lib/temporalio/client/workflow_update_wait_stage.rb +17 -0
  74. data/lib/temporalio/client.rb +404 -0
  75. data/lib/temporalio/common_enums.rb +24 -0
  76. data/lib/temporalio/converters/data_converter.rb +102 -0
  77. data/lib/temporalio/converters/failure_converter.rb +200 -0
  78. data/lib/temporalio/converters/payload_codec.rb +26 -0
  79. data/lib/temporalio/converters/payload_converter/binary_null.rb +34 -0
  80. data/lib/temporalio/converters/payload_converter/binary_plain.rb +35 -0
  81. data/lib/temporalio/converters/payload_converter/binary_protobuf.rb +42 -0
  82. data/lib/temporalio/converters/payload_converter/composite.rb +62 -0
  83. data/lib/temporalio/converters/payload_converter/encoding.rb +35 -0
  84. data/lib/temporalio/converters/payload_converter/json_plain.rb +44 -0
  85. data/lib/temporalio/converters/payload_converter/json_protobuf.rb +41 -0
  86. data/lib/temporalio/converters/payload_converter.rb +73 -0
  87. data/lib/temporalio/converters.rb +9 -0
  88. data/lib/temporalio/error/failure.rb +219 -0
  89. data/lib/temporalio/error.rb +147 -0
  90. data/lib/temporalio/internal/bridge/3.1/temporalio_bridge.bundle +0 -0
  91. data/lib/temporalio/internal/bridge/3.2/temporalio_bridge.bundle +0 -0
  92. data/lib/temporalio/internal/bridge/3.3/temporalio_bridge.bundle +0 -0
  93. data/lib/temporalio/internal/bridge/api/activity_result/activity_result.rb +34 -0
  94. data/lib/temporalio/internal/bridge/api/activity_task/activity_task.rb +31 -0
  95. data/lib/temporalio/internal/bridge/api/child_workflow/child_workflow.rb +33 -0
  96. data/lib/temporalio/internal/bridge/api/common/common.rb +26 -0
  97. data/lib/temporalio/internal/bridge/api/core_interface.rb +36 -0
  98. data/lib/temporalio/internal/bridge/api/external_data/external_data.rb +27 -0
  99. data/lib/temporalio/internal/bridge/api/workflow_activation/workflow_activation.rb +52 -0
  100. data/lib/temporalio/internal/bridge/api/workflow_commands/workflow_commands.rb +54 -0
  101. data/lib/temporalio/internal/bridge/api/workflow_completion/workflow_completion.rb +30 -0
  102. data/lib/temporalio/internal/bridge/api.rb +3 -0
  103. data/lib/temporalio/internal/bridge/client.rb +90 -0
  104. data/lib/temporalio/internal/bridge/runtime.rb +53 -0
  105. data/lib/temporalio/internal/bridge/testing.rb +46 -0
  106. data/lib/temporalio/internal/bridge/worker.rb +83 -0
  107. data/lib/temporalio/internal/bridge.rb +36 -0
  108. data/lib/temporalio/internal/client/implementation.rb +525 -0
  109. data/lib/temporalio/internal/proto_utils.rb +54 -0
  110. data/lib/temporalio/internal/worker/activity_worker.rb +345 -0
  111. data/lib/temporalio/internal/worker/multi_runner.rb +169 -0
  112. data/lib/temporalio/internal.rb +7 -0
  113. data/lib/temporalio/retry_policy.rb +51 -0
  114. data/lib/temporalio/runtime.rb +271 -0
  115. data/lib/temporalio/scoped_logger.rb +96 -0
  116. data/lib/temporalio/search_attributes.rb +300 -0
  117. data/lib/temporalio/testing/activity_environment.rb +132 -0
  118. data/lib/temporalio/testing/workflow_environment.rb +137 -0
  119. data/lib/temporalio/testing.rb +10 -0
  120. data/lib/temporalio/version.rb +5 -0
  121. data/lib/temporalio/worker/activity_executor/fiber.rb +49 -0
  122. data/lib/temporalio/worker/activity_executor/thread_pool.rb +254 -0
  123. data/lib/temporalio/worker/activity_executor.rb +55 -0
  124. data/lib/temporalio/worker/interceptor.rb +88 -0
  125. data/lib/temporalio/worker/tuner.rb +151 -0
  126. data/lib/temporalio/worker.rb +426 -0
  127. data/lib/temporalio/workflow_history.rb +22 -0
  128. data/lib/temporalio.rb +7 -0
  129. data/temporalio.gemspec +28 -0
  130. metadata +191 -0
@@ -0,0 +1,404 @@
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/workflow_execution'
10
+ require 'temporalio/client/workflow_execution_count'
11
+ require 'temporalio/client/workflow_handle'
12
+ require 'temporalio/client/workflow_query_reject_condition'
13
+ require 'temporalio/common_enums'
14
+ require 'temporalio/converters'
15
+ require 'temporalio/error'
16
+ require 'temporalio/internal/client/implementation'
17
+ require 'temporalio/retry_policy'
18
+ require 'temporalio/runtime'
19
+ require 'temporalio/search_attributes'
20
+
21
+ module Temporalio
22
+ # Client for accessing Temporal.
23
+ #
24
+ # Most users will use {connect} to connect a client. The {workflow_service} method provides access to a raw gRPC
25
+ # client. To create another client on the same connection, like for a different namespace, {options} may be used to
26
+ # get the options as a struct which can then be dup'd, altered, and splatted as kwargs to the constructor (e.g.
27
+ # +Client.new(**my_options.to_h)+).
28
+ #
29
+ # Clients are thread-safe and are meant to be reused for the life of the application. They are built to work in both
30
+ # synchronous and asynchronous contexts. Internally they use callbacks based on {::Queue} which means they are
31
+ # Fiber-compatible.
32
+ class Client
33
+ # Options as returned from {options} for +**to_h+ splat use in {initialize}. See {initialize} for details.
34
+ Options = Struct.new(
35
+ :connection,
36
+ :namespace,
37
+ :data_converter,
38
+ :interceptors,
39
+ :logger,
40
+ :default_workflow_query_reject_condition,
41
+ keyword_init: true
42
+ )
43
+
44
+ # Connect to Temporal server. This is a shortcut for +Connection.new+ followed by +Client.new+.
45
+ #
46
+ # @param target_host [String] +host:port+ for the Temporal server. For local development, this is often
47
+ # +localhost:7233+.
48
+ # @param namespace [String] Namespace to use for client calls.
49
+ # @param api_key [String, nil] API key for Temporal. This becomes the +Authorization+ HTTP header with +"Bearer "+
50
+ # prepended. This is only set if RPC metadata doesn't already have an +authorization+ key.
51
+ # @param tls [Boolean, Connection::TLSOptions] If false, do not use TLS. If true, use system default TLS options. If
52
+ # TLS options are present, those TLS options will be used.
53
+ # @param data_converter [Converters::DataConverter] Data converter to use for all data conversions to/from payloads.
54
+ # @param interceptors [Array<Interceptor>] Set of interceptors that are chained together to allow intercepting of
55
+ # client calls. The earlier interceptors wrap the later ones. Any interceptors that also implement worker
56
+ # interceptor will be used as worker interceptors too so they should not be given separately when creating a
57
+ # worker.
58
+ # @param logger [Logger] Logger to use for this client and any workers made from this client. Defaults to stdout
59
+ # with warn level. Callers setting this logger are responsible for closing it.
60
+ # @param default_workflow_query_reject_condition [WorkflowQueryRejectCondition, nil] Default rejection
61
+ # condition for workflow queries if not set during query. See {WorkflowHandle.query} for details on the
62
+ # rejection condition.
63
+ # @param rpc_metadata [Hash<String, String>] Headers to use for all calls to the server. Keys here can be overriden
64
+ # by per-call RPC metadata keys.
65
+ # @param rpc_retry [Connection::RPCRetryOptions] Retry options for direct service calls (when opted in) or all
66
+ # high-level calls made by this client (which all opt-in to retries by default).
67
+ # @param identity [String] Identity for this client.
68
+ # @param keep_alive [Connection::KeepAliveOptions] Keep-alive options for the client connection. Can be set to +nil+
69
+ # to disable.
70
+ # @param http_connect_proxy [Connection::HTTPConnectProxyOptions, nil] Options for HTTP CONNECT proxy.
71
+ # @param runtime [Runtime] Runtime for this client.
72
+ # @param lazy_connect [Boolean] If true, the client will not connect until the first call is attempted or a worker
73
+ # is created with it. Lazy clients cannot be used for workers if they have not performed a connection.
74
+ #
75
+ # @return [Client] Connected client.
76
+ #
77
+ # @see Connection.initialize
78
+ # @see initialize
79
+ def self.connect(
80
+ target_host,
81
+ namespace,
82
+ api_key: nil,
83
+ tls: false,
84
+ data_converter: Converters::DataConverter.default,
85
+ interceptors: [],
86
+ logger: Logger.new($stdout, level: Logger::WARN),
87
+ default_workflow_query_reject_condition: nil,
88
+ rpc_metadata: {},
89
+ rpc_retry: Connection::RPCRetryOptions.new,
90
+ identity: "#{Process.pid}@#{Socket.gethostname}",
91
+ keep_alive: Connection::KeepAliveOptions.new, # Set to nil to disable
92
+ http_connect_proxy: nil,
93
+ runtime: Runtime.default,
94
+ lazy_connect: false
95
+ )
96
+ Client.new(
97
+ connection: Connection.new(
98
+ target_host:,
99
+ api_key:,
100
+ tls:,
101
+ rpc_metadata:,
102
+ rpc_retry:,
103
+ identity:,
104
+ keep_alive:,
105
+ http_connect_proxy:,
106
+ runtime:,
107
+ lazy_connect:
108
+ ),
109
+ namespace:,
110
+ data_converter:,
111
+ interceptors:,
112
+ logger:,
113
+ default_workflow_query_reject_condition:
114
+ )
115
+ end
116
+
117
+ # @return [Options] Frozen options for this client which has the same attributes as {initialize}.
118
+ attr_reader :options
119
+
120
+ # Create a client from an existing connection. Most users will prefer {connect} instead. Parameters here match
121
+ # {Options} returned from {options} by intention so options can be dup'd, altered, and splatted to create a new
122
+ # client.
123
+ #
124
+ # @param connection [Connection] Existing connection to create a client from.
125
+ # @param namespace [String] Namespace to use for client calls.
126
+ # @param data_converter [Converters::DataConverter] Data converter to use for all data conversions to/from payloads.
127
+ # @param interceptors [Array<Interceptor>] Set of interceptors that are chained together to allow intercepting of
128
+ # client calls. The earlier interceptors wrap the later ones. Any interceptors that also implement worker
129
+ # interceptor will be used as worker interceptors too so they should not be given separately when creating a
130
+ # worker.
131
+ # @param logger [Logger] Logger to use for this client and any workers made from this client. Defaults to stdout
132
+ # with warn level. Callers setting this logger are responsible for closing it.
133
+ # @param default_workflow_query_reject_condition [WorkflowQueryRejectCondition, nil] Default rejection condition for
134
+ # workflow queries if not set during query. See {WorkflowHandle.query} for details on the rejection condition.
135
+ #
136
+ # @see connect
137
+ def initialize(
138
+ connection:,
139
+ namespace:,
140
+ data_converter: DataConverter.default,
141
+ interceptors: [],
142
+ logger: Logger.new($stdout, level: Logger::WARN),
143
+ default_workflow_query_reject_condition: nil
144
+ )
145
+ @options = Options.new(
146
+ connection:,
147
+ namespace:,
148
+ data_converter:,
149
+ interceptors:,
150
+ logger:,
151
+ default_workflow_query_reject_condition:
152
+ ).freeze
153
+ # Initialize interceptors
154
+ @impl = interceptors.reverse_each.reduce(Internal::Client::Implementation.new(self)) do |acc, int|
155
+ int.intercept_client(acc)
156
+ end
157
+ end
158
+
159
+ # @return [Connection] Underlying connection for this client.
160
+ def connection
161
+ @options.connection
162
+ end
163
+
164
+ # @return [String] Namespace used in calls by this client.
165
+ def namespace
166
+ @options.namespace
167
+ end
168
+
169
+ # @return [DataConverter] Data converter used by this client.
170
+ def data_converter
171
+ @options.data_converter
172
+ end
173
+
174
+ # @return [Connection::WorkflowService] Raw gRPC workflow service.
175
+ def workflow_service
176
+ connection.workflow_service
177
+ end
178
+
179
+ # @return [Connection::OperatorService] Raw gRPC operator service.
180
+ def operator_service
181
+ connection.operator_service
182
+ end
183
+
184
+ # Start a workflow and return its handle.
185
+ #
186
+ # @param workflow [Workflow, String] Name of the workflow
187
+ # @param args [Array<Object>] Arguments to the workflow.
188
+ # @param id [String] Unique identifier for the workflow execution.
189
+ # @param task_queue [String] Task queue to run the workflow on.
190
+ # @param execution_timeout [Float, nil] Total workflow execution timeout in seconds including retries and continue
191
+ # as new.
192
+ # @param run_timeout [Float, nil] Timeout of a single workflow run in seconds.
193
+ # @param task_timeout [Float, nil] Timeout of a single workflow task in seconds.
194
+ # @param id_reuse_policy [WorkflowIDReusePolicy] How already-existing IDs are treated.
195
+ # @param id_conflict_policy [WorkflowIDConflictPolicy] How already-running workflows of the same ID are treated.
196
+ # Default is unspecified which effectively means fail the start attempt. This cannot be set if `id_reuse_policy`
197
+ # is set to terminate if running.
198
+ # @param retry_policy [RetryPolicy, nil] Retry policy for the workflow.
199
+ # @param cron_schedule [String, nil] Cron schedule. Users should use schedules instead of this.
200
+ # @param memo [Hash<String, Object>, nil] Memo for the workflow.
201
+ # @param search_attributes [SearchAttributes, nil] Search attributes for the workflow.
202
+ # @param start_delay [Float, nil] Amount of time in seconds to wait before starting the workflow. This does not work
203
+ # with `cron_schedule`.
204
+ # @param request_eager_start [Boolean] Potentially reduce the latency to start this workflow by encouraging the
205
+ # server to start it on a local worker running with this same client. This is currently experimental.
206
+ # @param rpc_metadata [Hash<String, String>, nil] Headers to include on the RPC call.
207
+ # @param rpc_timeout [Float, nil] Number of seconds before timeout.
208
+ #
209
+ # @return [WorkflowHandle] A workflow handle to the started workflow.
210
+ # @raise [Error::WorkflowAlreadyStartedError] Workflow already exists.
211
+ # @raise [Error::RPCError] RPC error from call.
212
+ def start_workflow(
213
+ workflow,
214
+ *args,
215
+ id:,
216
+ task_queue:,
217
+ execution_timeout: nil,
218
+ run_timeout: nil,
219
+ task_timeout: nil,
220
+ id_reuse_policy: WorkflowIDReusePolicy::ALLOW_DUPLICATE,
221
+ id_conflict_policy: WorkflowIDConflictPolicy::UNSPECIFIED,
222
+ retry_policy: nil,
223
+ cron_schedule: nil,
224
+ memo: nil,
225
+ search_attributes: nil,
226
+ start_delay: nil,
227
+ request_eager_start: false,
228
+ rpc_metadata: nil,
229
+ rpc_timeout: nil
230
+ )
231
+ @impl.start_workflow(Interceptor::StartWorkflowInput.new(
232
+ workflow:,
233
+ args:,
234
+ workflow_id: id,
235
+ task_queue:,
236
+ execution_timeout:,
237
+ run_timeout:,
238
+ task_timeout:,
239
+ id_reuse_policy:,
240
+ id_conflict_policy:,
241
+ retry_policy:,
242
+ cron_schedule:,
243
+ memo:,
244
+ search_attributes:,
245
+ start_delay:,
246
+ request_eager_start:,
247
+ headers: {},
248
+ rpc_metadata:,
249
+ rpc_timeout:
250
+ ))
251
+ end
252
+
253
+ # Start a workflow and wait for its result. This is a shortcut for {start_workflow} + {WorkflowHandle.result}.
254
+ #
255
+ # @param workflow [Workflow, String] Name of the workflow
256
+ # @param args [Array<Object>] Arguments to the workflow.
257
+ # @param id [String] Unique identifier for the workflow execution.
258
+ # @param task_queue [String] Task queue to run the workflow on.
259
+ # @param execution_timeout [Float, nil] Total workflow execution timeout in seconds including retries and continue
260
+ # as new.
261
+ # @param run_timeout [Float, nil] Timeout of a single workflow run in seconds.
262
+ # @param task_timeout [Float, nil] Timeout of a single workflow task in seconds.
263
+ # @param id_reuse_policy [WorkflowIDReusePolicy] How already-existing IDs are treated.
264
+ # @param id_conflict_policy [WorkflowIDConflictPolicy] How already-running workflows of the same ID are treated.
265
+ # Default is unspecified which effectively means fail the start attempt. This cannot be set if `id_reuse_policy`
266
+ # is set to terminate if running.
267
+ # @param retry_policy [RetryPolicy, nil] Retry policy for the workflow.
268
+ # @param cron_schedule [String, nil] Cron schedule. Users should use schedules instead of this.
269
+ # @param memo [Hash<String, Object>, nil] Memo for the workflow.
270
+ # @param search_attributes [SearchAttributes, nil] Search attributes for the workflow.
271
+ # @param start_delay [Float, nil] Amount of time in seconds to wait before starting the workflow. This does not work
272
+ # with `cron_schedule`.
273
+ # @param request_eager_start [Boolean] Potentially reduce the latency to start this workflow by encouraging the
274
+ # server to start it on a local worker running with this same client. This is currently experimental.
275
+ # @param rpc_metadata [Hash<String, String>, nil] Headers to include on the RPC call.
276
+ # @param rpc_timeout [Float, nil] Number of seconds before timeout.
277
+ #
278
+ # @return [Object] Successful result of the workflow.
279
+ # @raise [Error::WorkflowAlreadyStartedError] Workflow already exists.
280
+ # @raise [Error::WorkflowFailedError] Workflow failed with +cause+ as the cause.
281
+ # @raise [Error::RPCError] RPC error from call.
282
+ def execute_workflow(
283
+ workflow,
284
+ *args,
285
+ id:,
286
+ task_queue:,
287
+ execution_timeout: nil,
288
+ run_timeout: nil,
289
+ task_timeout: nil,
290
+ id_reuse_policy: WorkflowIDReusePolicy::ALLOW_DUPLICATE,
291
+ id_conflict_policy: WorkflowIDConflictPolicy::UNSPECIFIED,
292
+ retry_policy: nil,
293
+ cron_schedule: nil,
294
+ memo: nil,
295
+ search_attributes: nil,
296
+ start_delay: nil,
297
+ request_eager_start: false,
298
+ rpc_metadata: nil,
299
+ rpc_timeout: nil
300
+ )
301
+ start_workflow(
302
+ workflow,
303
+ *args,
304
+ id:,
305
+ task_queue:,
306
+ execution_timeout:,
307
+ run_timeout:,
308
+ task_timeout:,
309
+ id_reuse_policy:,
310
+ id_conflict_policy:,
311
+ retry_policy:,
312
+ cron_schedule:,
313
+ memo:,
314
+ search_attributes:,
315
+ start_delay:,
316
+ request_eager_start:,
317
+ rpc_metadata:,
318
+ rpc_timeout:
319
+ ).result
320
+ end
321
+
322
+ # Get a workflow handle to an existing workflow by its ID.
323
+ #
324
+ # @param workflow_id [String] Workflow ID to get a handle to.
325
+ # @param run_id [String, nil] Run ID that will be used for all calls. Many choose to leave this unset which ensures
326
+ # interactions occur on the latest of the workflow ID.
327
+ # @param first_execution_run_id [String, nil] First execution run ID used for some calls like cancellation and
328
+ # termination to ensure the affected workflow is only within the same chain as this given run ID.
329
+ #
330
+ # @return [WorkflowHandle] The workflow handle.
331
+ def workflow_handle(
332
+ workflow_id,
333
+ run_id: nil,
334
+ first_execution_run_id: nil
335
+ )
336
+ WorkflowHandle.new(client: self, id: workflow_id, run_id:, result_run_id: run_id, first_execution_run_id:)
337
+ end
338
+
339
+ # List workflows.
340
+ #
341
+ # @param query [String, nil] A Temporal visibility list filter.
342
+ # @param rpc_metadata [Hash<String, String>, nil] Headers to include on the RPC call.
343
+ # @param rpc_timeout [Float, nil] Number of seconds before timeout.
344
+ #
345
+ # @return [Enumerator<WorkflowExecution>] Enumerable workflow executions.
346
+ #
347
+ # @raise [Error::RPCError] RPC error from call.
348
+ #
349
+ # @see https://docs.temporal.io/visibility
350
+ def list_workflows(
351
+ query = nil,
352
+ rpc_metadata: nil,
353
+ rpc_timeout: nil
354
+ )
355
+ @impl.list_workflows(Interceptor::ListWorkflowsInput.new(
356
+ query:,
357
+ rpc_metadata:,
358
+ rpc_timeout:
359
+ ))
360
+ end
361
+
362
+ # Count workflows.
363
+ #
364
+ # @param query [String, nil] A Temporal visibility list filter.
365
+ # @param rpc_metadata [Hash<String, String>, nil] Headers to include on the RPC call.
366
+ # @param rpc_timeout [Float, nil] Number of seconds before timeout.
367
+ #
368
+ # @return [WorkflowExecutionCount] Count of workflows.
369
+ #
370
+ # @raise [Error::RPCError] RPC error from call.
371
+ #
372
+ # @see https://docs.temporal.io/visibility
373
+ def count_workflows(
374
+ query = nil,
375
+ rpc_metadata: nil,
376
+ rpc_timeout: nil
377
+ )
378
+ @impl.count_workflows(Interceptor::CountWorkflowsInput.new(
379
+ query:,
380
+ rpc_metadata:,
381
+ rpc_timeout:
382
+ ))
383
+ end
384
+
385
+ # Get an async activity handle.
386
+ #
387
+ # @param task_token_or_id_reference [String, ActivityIDReference] Task token string or activity ID reference.
388
+ # @return [AsyncActivityHandle]
389
+ def async_activity_handle(task_token_or_id_reference)
390
+ if task_token_or_id_reference.is_a?(ActivityIDReference)
391
+ AsyncActivityHandle.new(client: self, task_token: nil, id_reference: task_token_or_id_reference)
392
+ elsif task_token_or_id_reference.is_a?(String)
393
+ AsyncActivityHandle.new(client: self, task_token: task_token_or_id_reference, id_reference: nil)
394
+ else
395
+ raise ArgumentError, 'Must be a string task token or an ActivityIDReference'
396
+ end
397
+ end
398
+
399
+ # @!visibility private
400
+ def _impl
401
+ @impl
402
+ end
403
+ end
404
+ end
@@ -0,0 +1,24 @@
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_DUPLICATE = Api::Enums::V1::WorkflowIdReusePolicy::WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE
11
+ ALLOW_DUPLICATE_FAILED_ONLY =
12
+ Api::Enums::V1::WorkflowIdReusePolicy::WORKFLOW_ID_REUSE_POLICY_ALLOW_DUPLICATE_FAILED_ONLY
13
+ REJECT_DUPLICATE = Api::Enums::V1::WorkflowIdReusePolicy::WORKFLOW_ID_REUSE_POLICY_REJECT_DUPLICATE
14
+ TERMINATE_IF_RUNNING = Api::Enums::V1::WorkflowIdReusePolicy::WORKFLOW_ID_REUSE_POLICY_TERMINATE_IF_RUNNING
15
+ end
16
+
17
+ # How already-running workflows of the same ID are handled on start.
18
+ module WorkflowIDConflictPolicy
19
+ UNSPECIFIED = Api::Enums::V1::WorkflowIdConflictPolicy::WORKFLOW_ID_CONFLICT_POLICY_UNSPECIFIED
20
+ FAIL = Api::Enums::V1::WorkflowIdConflictPolicy::WORKFLOW_ID_CONFLICT_POLICY_FAIL
21
+ USE_EXISTING = Api::Enums::V1::WorkflowIdConflictPolicy::WORKFLOW_ID_CONFLICT_POLICY_USE_EXISTING
22
+ TERMINATE_EXISTING = Api::Enums::V1::WorkflowIdConflictPolicy::WORKFLOW_ID_CONFLICT_POLICY_TERMINATE_EXISTING
23
+ end
24
+ end
@@ -0,0 +1,102 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'temporalio/api'
4
+ require 'temporalio/converters/failure_converter'
5
+ require 'temporalio/converters/payload_converter'
6
+
7
+ module Temporalio
8
+ module Converters
9
+ # Data converter for converting/encoding payloads to/from Ruby values.
10
+ class DataConverter
11
+ # @return [PayloadConverter] Payload converter. This must be Ractor shareable.
12
+ attr_reader :payload_converter
13
+
14
+ # @return [FailureConverter] Failure converter. This must be Ractor shareable.
15
+ attr_reader :failure_converter
16
+
17
+ # @return [PayloadCodec, nil] Optional codec for encoding/decoding payload bytes such as for encryption.
18
+ attr_reader :payload_codec
19
+
20
+ # @return [DataConverter] Default data converter.
21
+ def self.default
22
+ @default ||= DataConverter.new
23
+ end
24
+
25
+ # Create data converter.
26
+ #
27
+ # @param payload_converter [PayloadConverter] Payload converter to use. This must be Ractor shareable.
28
+ # @param failure_converter [FailureConverter] Failure converter to use. This must be Ractor shareable.
29
+ # @param payload_codec [PayloadCodec, nil] Payload codec to use.
30
+ def initialize(
31
+ payload_converter: PayloadConverter.default,
32
+ failure_converter: FailureConverter.default,
33
+ payload_codec: nil
34
+ )
35
+ raise 'Payload converter not shareable' unless Ractor.shareable?(payload_converter)
36
+ raise 'Failure converter not shareable' unless Ractor.shareable?(failure_converter)
37
+
38
+ @payload_converter = payload_converter
39
+ @failure_converter = failure_converter
40
+ @payload_codec = payload_codec
41
+ end
42
+
43
+ # Convert a Ruby value to a payload and encode it.
44
+ #
45
+ # @param value [Object] Ruby value.
46
+ # @return [Api::Common::V1::Payload] Converted and encoded payload.
47
+ def to_payload(value)
48
+ payload = payload_converter.to_payload(value)
49
+ payload = payload_codec.encode([payload]).first if payload_codec
50
+ payload
51
+ end
52
+
53
+ # Convert multiple Ruby values to a payload set and encode it.
54
+ #
55
+ # @param values [Object] Ruby values, converted to array via {::Array}.
56
+ # @return [Api::Common::V1::Payloads] Converted and encoded payload set.
57
+ def to_payloads(values)
58
+ payloads = payload_converter.to_payloads(values)
59
+ payloads.payloads.replace(payload_codec.encode(payloads.payloads)) if payload_codec && !payloads.payloads.empty?
60
+ payloads
61
+ end
62
+
63
+ # Decode and convert a payload to a Ruby value.
64
+ #
65
+ # @param payload [Api::Common::V1::Payload] Encoded payload.
66
+ # @return [Object] Decoded and converted Ruby value.
67
+ def from_payload(payload)
68
+ payload = payload_codec.decode([payload]).first if payload_codec
69
+ payload_converter.from_payload(payload)
70
+ end
71
+
72
+ # Decode and convert a payload set to Ruby values.
73
+ #
74
+ # @param payloads [Api::Common::V1::Payloads, nil] Encoded payload set.
75
+ # @return [Array<Object>] Decoded and converted Ruby values.
76
+ def from_payloads(payloads)
77
+ return [] unless payloads && !payloads.payloads.empty?
78
+
79
+ if payload_codec && !payloads.payloads.empty?
80
+ payloads = Api::Common::V1::Payloads.new(payloads: payload_codec.decode(payloads.payloads))
81
+ end
82
+ payload_converter.from_payloads(payloads)
83
+ end
84
+
85
+ # Convert a Ruby error to a Temporal failure and encode it.
86
+ #
87
+ # @param error [Exception] Ruby error.
88
+ # @return [Api::Failure::V1::Failure] Converted and encoded failure.
89
+ def to_failure(error)
90
+ failure_converter.to_failure(error, self)
91
+ end
92
+
93
+ # Decode and convert a Temporal failure to a Ruby error.
94
+ #
95
+ # @param failure [Api::Failure::V1::Failure] Encoded failure.
96
+ # @return [Exception] Decoded and converted Ruby error.
97
+ def from_failure(failure)
98
+ failure_converter.from_failure(failure, self)
99
+ end
100
+ end
101
+ end
102
+ end