temporalio 0.4.0-aarch64-linux-musl

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