temporalio 0.2.0-x86_64-darwin

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 (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,270 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'socket'
4
+ require 'temporalio/client/connection/cloud_service'
5
+ require 'temporalio/client/connection/operator_service'
6
+ require 'temporalio/client/connection/workflow_service'
7
+ require 'temporalio/internal/bridge'
8
+ require 'temporalio/internal/bridge/client'
9
+ require 'temporalio/runtime'
10
+ require 'temporalio/version'
11
+
12
+ module Temporalio
13
+ class Client
14
+ # Connection to Temporal server that is not namespace specific. Most users will use {Client.connect} instead of this
15
+ # directly.
16
+ class Connection
17
+ # Options as returned from {options} for +**to_h+ splat use in {initialize}. See {initialize} for details.
18
+ Options = Struct.new(
19
+ :target_host,
20
+ :api_key,
21
+ :tls,
22
+ :rpc_metadata,
23
+ :rpc_retry,
24
+ :identity,
25
+ :keep_alive,
26
+ :http_connect_proxy,
27
+ :runtime,
28
+ :lazy_connect,
29
+ keyword_init: true
30
+ )
31
+
32
+ # TLS options. All attributes are optional, and an empty options set just enables default TLS.
33
+ #
34
+ # @!attribute client_cert
35
+ # @return [String, nil] Client certificate for mTLS. Must be combined with {client_private_key}.
36
+ # @!attribute client_private_key
37
+ # @return [String, nil] Client private key for mTLS. Must be combined with {client_cert}.
38
+ # @!attribute server_root_ca_cert
39
+ # @return [String, nil] Root CA certificate to validate the server certificate against. This is only needed for
40
+ # self-hosted servers with self-signed server certificates.
41
+ # @!attribute domain
42
+ # @return [String, nil] SNI override. This is only needed for self-hosted servers with certificates that do not
43
+ # match the hostname being connected to.
44
+ TLSOptions = Struct.new(
45
+ :client_cert,
46
+ :client_private_key,
47
+ :server_root_ca_cert,
48
+ :domain,
49
+ keyword_init: true
50
+ )
51
+
52
+ # Retry options for server calls when retry is enabled (which it is by default on all high-level {Client} calls).
53
+ # For most users, the default is preferred.
54
+ #
55
+ # @!attribute initial_interval
56
+ # @return [Float] Initial backoff interval, default 0.1.
57
+ # @!attribute randomization_factor
58
+ # @return [Float] Randomization jitter to add, default 0.2.
59
+ # @!attribute multiplier
60
+ # @return [Float] Backoff multiplier, default 1.5.
61
+ # @!attribute max_interval
62
+ # @return [Float] Maximum backoff interval, default 5.0.
63
+ # @!attribute max_elapsed_time
64
+ # @return [Float] Maximum total time, default 10.0. Can use 0 for no max.
65
+ # @!attribute max_retries
66
+ # @return [Integer] Maximum number of retries, default 10.
67
+ RPCRetryOptions = Struct.new(
68
+ :initial_interval,
69
+ :randomization_factor,
70
+ :multiplier,
71
+ :max_interval,
72
+ :max_elapsed_time,
73
+ :max_retries,
74
+ keyword_init: true
75
+ ) do
76
+ def initialize(**kwargs)
77
+ # @type var kwargs: untyped
78
+ kwargs[:initial_interval] = 0.1 unless kwargs.key?(:initial_interval)
79
+ kwargs[:randomization_factor] = 0.2 unless kwargs.key?(:randomization_factor)
80
+ kwargs[:multiplier] = 1.5 unless kwargs.key?(:multiplier)
81
+ kwargs[:max_interval] = 5.0 unless kwargs.key?(:max_interval)
82
+ kwargs[:max_elapsed_time] = 10.0 unless kwargs.key?(:max_elapsed_time)
83
+ kwargs[:max_retries] = 10 unless kwargs.key?(:max_retries)
84
+ super
85
+ end
86
+ end
87
+
88
+ # Keep-alive options for client connections. For most users, the default is preferred.
89
+ #
90
+ # @!attribute interval
91
+ # @return [Float] Interval to send HTTP2 keep alive pings, default 30.0.
92
+ # @!attribute timeout
93
+ # @return [Float] Timeout that the keep alive must be responded to within or the connection will be closed,
94
+ # default 15.0.
95
+ KeepAliveOptions = Struct.new(
96
+ :interval,
97
+ :timeout,
98
+ keyword_init: true
99
+ ) do
100
+ def initialize(**kwargs)
101
+ # @type var kwargs: untyped
102
+ kwargs[:interval] = 30.0 unless kwargs.key?(:interval)
103
+ kwargs[:timeout] = 15.0 unless kwargs.key?(:timeout)
104
+ super
105
+ end
106
+ end
107
+
108
+ # Options for HTTP CONNECT proxy for client connections.
109
+ #
110
+ # @!attribute target_host
111
+ # @return [String] Target host:port for the HTTP CONNECT proxy.
112
+ # @!attribute basic_auth_user
113
+ # @return [String, nil] User for HTTP basic auth for the proxy, must be combined with {basic_auth_pass}.
114
+ # @!attribute basic_auth_pass
115
+ # @return [String, nil] Pass for HTTP basic auth for the proxy, must be combined with {basic_auth_user}.
116
+ HTTPConnectProxyOptions = Struct.new(
117
+ :target_host,
118
+ :basic_auth_user, # Optional
119
+ :basic_auth_pass, # Optional,
120
+ keyword_init: true
121
+ )
122
+
123
+ # @return [Options] Frozen options for this client which has the same attributes as {initialize}.
124
+ attr_reader :options
125
+
126
+ # @return [WorkflowService] Raw gRPC workflow service.
127
+ attr_reader :workflow_service
128
+
129
+ # @return [OperatorService] Raw gRPC operator service.
130
+ attr_reader :operator_service
131
+
132
+ # @return [CloudService] Raw gRPC cloud service.
133
+ attr_reader :cloud_service
134
+
135
+ # Connect to Temporal server. Most users will use {Client.connect} instead of this directly. Parameters here match
136
+ # {Options} returned from {options} by intention so options can be dup'd, altered, splatted to create a new
137
+ # connection.
138
+ #
139
+ # @param target_host [String] +host:port+ for the Temporal server. For local development, this is often
140
+ # +localhost:7233+.
141
+ # @param api_key [String, nil] API key for Temporal. This becomes the +Authorization+ HTTP header with +"Bearer "+
142
+ # prepended. This is only set if RPC metadata doesn't already have an +authorization+ key.
143
+ # @param tls [Boolean, TLSOptions] If false, do not use TLS. If true, use system default TLS options. If TLS
144
+ # options are present, those TLS options will be used.
145
+ # @param rpc_metadata [Hash<String, String>] Headers to use for all calls to the server. Keys here can be
146
+ # overriden by per-call RPC metadata keys.
147
+ # @param rpc_retry [RPCRetryOptions] Retry options for direct service calls (when opted in) or all high-level
148
+ # calls made by this client (which all opt-in to retries by default).
149
+ # @param identity [String] Identity for this client.
150
+ # @param keep_alive [KeepAliveOptions] Keep-alive options for the client connection. Can be set to +nil+ to
151
+ # disable.
152
+ # @param http_connect_proxy [HTTPConnectProxyOptions, nil] Options for HTTP CONNECT proxy.
153
+ # @param runtime [Runtime] Runtime for this client.
154
+ # @param lazy_connect [Boolean] If true, there is no connection until the first call is attempted or a worker
155
+ # is created with it. Clients from lazy connections cannot be used for workers if they have not performed a
156
+ # connection.
157
+ #
158
+ # @see Client.connect
159
+ def initialize(
160
+ target_host:,
161
+ api_key: nil,
162
+ tls: false,
163
+ rpc_metadata: {},
164
+ rpc_retry: RPCRetryOptions.new,
165
+ identity: "#{Process.pid}@#{Socket.gethostname}",
166
+ keep_alive: KeepAliveOptions.new,
167
+ http_connect_proxy: nil,
168
+ runtime: Runtime.default,
169
+ lazy_connect: false
170
+ )
171
+ @options = Options.new(
172
+ target_host:,
173
+ api_key:,
174
+ tls:,
175
+ rpc_metadata:,
176
+ rpc_retry:,
177
+ identity:,
178
+ keep_alive:,
179
+ http_connect_proxy:,
180
+ runtime:,
181
+ lazy_connect:
182
+ ).freeze
183
+ # Create core client now if not lazy
184
+ _core_client unless lazy_connect
185
+ # Create service instances
186
+ @workflow_service = WorkflowService.new(self)
187
+ @operator_service = OperatorService.new(self)
188
+ @cloud_service = CloudService.new(self)
189
+ end
190
+
191
+ # @return [String] Target host this connection is connected to.
192
+ def target_host
193
+ @options.target_host
194
+ end
195
+
196
+ # @return [String] Client identity.
197
+ def identity
198
+ @options.identity
199
+ end
200
+
201
+ # @return [Boolean] Whether this connection is connected. This is always `true` unless `lazy_connect` option was
202
+ # originally set, in which case this will be `false` until the first call is made.
203
+ def connected?
204
+ !@core_client.nil?
205
+ end
206
+
207
+ # @!visibility private
208
+ def _core_client
209
+ # If lazy, this needs to be done under mutex
210
+ if @options.lazy_connect
211
+ @core_client_mutex ||= Mutex.new
212
+ @core_client_mutex.synchronize do
213
+ @core_client ||= new_core_client
214
+ end
215
+ else
216
+ @core_client ||= new_core_client
217
+ end
218
+ end
219
+
220
+ private
221
+
222
+ def new_core_client
223
+ Internal::Bridge.assert_fiber_compatibility!
224
+
225
+ options = Internal::Bridge::Client::Options.new(
226
+ target_host: @options.target_host,
227
+ client_name: 'temporal-ruby',
228
+ client_version: VERSION,
229
+ rpc_metadata: @options.rpc_metadata,
230
+ api_key: @options.api_key,
231
+ rpc_retry: Internal::Bridge::Client::RPCRetryOptions.new(
232
+ initial_interval: @options.rpc_retry.initial_interval,
233
+ randomization_factor: @options.rpc_retry.randomization_factor,
234
+ multiplier: @options.rpc_retry.multiplier,
235
+ max_interval: @options.rpc_retry.max_interval,
236
+ max_elapsed_time: @options.rpc_retry.max_elapsed_time,
237
+ max_retries: @options.rpc_retry.max_retries
238
+ ),
239
+ identity: @options.identity || "#{Process.pid}@#{Socket.gethostname}"
240
+ )
241
+ if @options.tls
242
+ options.tls = if @options.tls.is_a?(TLSOptions)
243
+ Internal::Bridge::Client::TLSOptions.new(
244
+ client_cert: @options.tls.client_cert, # steep:ignore
245
+ client_private_key: @options.tls.client_private_key, # steep:ignore
246
+ server_root_ca_cert: @options.tls.server_root_ca_cert, # steep:ignore
247
+ domain: @options.tls.domain # steep:ignore
248
+ )
249
+ else
250
+ Internal::Bridge::Client::TLSOptions.new
251
+ end
252
+ end
253
+ if @options.keep_alive
254
+ options.keep_alive = Internal::Bridge::Client::KeepAliveOptions.new(
255
+ interval: @options.keep_alive.interval,
256
+ timeout: @options.keep_alive.timeout
257
+ )
258
+ end
259
+ if @options.http_connect_proxy
260
+ options.http_connect_proxy = Internal::Bridge::Client::HTTPConnectProxyOptions.new(
261
+ target_host: @options.http_connect_proxy.target_host,
262
+ basic_auth_user: @options.http_connect_proxy.basic_auth_user,
263
+ basic_auth_pass: @options.http_connect_proxy.basic_auth_pass
264
+ )
265
+ end
266
+ Internal::Bridge::Client.new(@options.runtime._core_runtime, options)
267
+ end
268
+ end
269
+ end
270
+ end
@@ -0,0 +1,316 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Temporalio
4
+ class Client
5
+ # Mixin for intercepting clients. Classes that +include+ this should implement their own {intercept_client} that
6
+ # returns their own instance of {Outbound}.
7
+ #
8
+ # @note Input classes herein may get new required fields added and therefore the constructors of the Input classes
9
+ # may change in backwards incompatible ways. Users should not try to construct Input classes themselves.
10
+ module Interceptor
11
+ # Method called when intercepting a client. This is called upon client creation.
12
+ #
13
+ # @param next_interceptor [Outbound] Next interceptor in the chain that should be called. This is usually passed
14
+ # to {Outbound} constructor.
15
+ # @return [Outbound] Interceptor to be called for client calls.
16
+ def intercept_client(next_interceptor)
17
+ next_interceptor
18
+ end
19
+
20
+ # Input for {Outbound.start_workflow}.
21
+ StartWorkflowInput = Struct.new(
22
+ :workflow,
23
+ :args,
24
+ :workflow_id,
25
+ :task_queue,
26
+ :execution_timeout,
27
+ :run_timeout,
28
+ :task_timeout,
29
+ :id_reuse_policy,
30
+ :id_conflict_policy,
31
+ :retry_policy,
32
+ :cron_schedule,
33
+ :memo,
34
+ :search_attributes,
35
+ :start_delay,
36
+ :request_eager_start,
37
+ :headers,
38
+ :rpc_metadata,
39
+ :rpc_timeout,
40
+ keyword_init: true
41
+ )
42
+
43
+ # Input for {Outbound.list_workflows}.
44
+ ListWorkflowsInput = Struct.new(
45
+ :query,
46
+ :rpc_metadata,
47
+ :rpc_timeout,
48
+ keyword_init: true
49
+ )
50
+
51
+ # Input for {Outbound.count_workflows}.
52
+ CountWorkflowsInput = Struct.new(
53
+ :query,
54
+ :rpc_metadata,
55
+ :rpc_timeout,
56
+ keyword_init: true
57
+ )
58
+
59
+ # Input for {Outbound.describe_workflow}.
60
+ DescribeWorkflowInput = Struct.new(
61
+ :workflow_id,
62
+ :run_id,
63
+ :rpc_metadata,
64
+ :rpc_timeout,
65
+ keyword_init: true
66
+ )
67
+
68
+ # Input for {Outbound.fetch_workflow_history_events}.
69
+ FetchWorkflowHistoryEventsInput = Struct.new(
70
+ :workflow_id,
71
+ :run_id,
72
+ :wait_new_event,
73
+ :event_filter_type,
74
+ :skip_archival,
75
+ :rpc_metadata,
76
+ :rpc_timeout,
77
+ keyword_init: true
78
+ )
79
+
80
+ # Input for {Outbound.signal_workflow}.
81
+ SignalWorkflowInput = Struct.new(
82
+ :workflow_id,
83
+ :run_id,
84
+ :signal,
85
+ :args,
86
+ :headers,
87
+ :rpc_metadata,
88
+ :rpc_timeout,
89
+ keyword_init: true
90
+ )
91
+
92
+ # Input for {Outbound.query_workflow}.
93
+ QueryWorkflowInput = Struct.new(
94
+ :workflow_id,
95
+ :run_id,
96
+ :query,
97
+ :args,
98
+ :reject_condition,
99
+ :headers,
100
+ :rpc_metadata,
101
+ :rpc_timeout,
102
+ keyword_init: true
103
+ )
104
+
105
+ # Input for {Outbound.start_workflow_update}.
106
+ StartWorkflowUpdateInput = Struct.new(
107
+ :workflow_id,
108
+ :run_id,
109
+ :update_id,
110
+ :update,
111
+ :args,
112
+ :wait_for_stage,
113
+ :headers,
114
+ :rpc_metadata,
115
+ :rpc_timeout,
116
+ keyword_init: true
117
+ )
118
+
119
+ # Input for {Outbound.poll_workflow_update}.
120
+ PollWorkflowUpdateInput = Struct.new(
121
+ :workflow_id,
122
+ :run_id,
123
+ :update_id,
124
+ :rpc_metadata,
125
+ :rpc_timeout,
126
+ keyword_init: true
127
+ )
128
+
129
+ # Input for {Outbound.cancel_workflow}.
130
+ CancelWorkflowInput = Struct.new(
131
+ :workflow_id,
132
+ :run_id,
133
+ :first_execution_run_id,
134
+ :rpc_metadata,
135
+ :rpc_timeout,
136
+ keyword_init: true
137
+ )
138
+
139
+ # Input for {Outbound.terminate_workflow}.
140
+ TerminateWorkflowInput = Struct.new(
141
+ :workflow_id,
142
+ :run_id,
143
+ :first_execution_run_id,
144
+ :reason,
145
+ :details,
146
+ :rpc_metadata,
147
+ :rpc_timeout,
148
+ keyword_init: true
149
+ )
150
+
151
+ # Input for {Outbound.heartbeat_async_activity}.
152
+ HeartbeatAsyncActivityInput = Struct.new(
153
+ :task_token_or_id_reference,
154
+ :details,
155
+ :rpc_metadata,
156
+ :rpc_timeout,
157
+ keyword_init: true
158
+ )
159
+
160
+ # Input for {Outbound.complete_async_activity}.
161
+ CompleteAsyncActivityInput = Struct.new(
162
+ :task_token_or_id_reference,
163
+ :result,
164
+ :rpc_metadata,
165
+ :rpc_timeout,
166
+ keyword_init: true
167
+ )
168
+
169
+ # Input for {Outbound.fail_async_activity}.
170
+ FailAsyncActivityInput = Struct.new(
171
+ :task_token_or_id_reference,
172
+ :error,
173
+ :last_heartbeat_details,
174
+ :rpc_metadata,
175
+ :rpc_timeout,
176
+ keyword_init: true
177
+ )
178
+
179
+ # Input for {Outbound.report_cancellation_async_activity}.
180
+ ReportCancellationAsyncActivityInput = Struct.new(
181
+ :task_token_or_id_reference,
182
+ :details,
183
+ :rpc_metadata,
184
+ :rpc_timeout,
185
+ keyword_init: true
186
+ )
187
+
188
+ # Outbound interceptor for intercepting client calls. This should be extended by users needing to intercept client
189
+ # actions.
190
+ class Outbound
191
+ # @return [Outbound] Next interceptor in the chain.
192
+ attr_reader :next_interceptor
193
+
194
+ # Initialize outbound with the next interceptor in the chain.
195
+ #
196
+ # @param next_interceptor [Outbound] Next interceptor in the chain.
197
+ def initialize(next_interceptor)
198
+ @next_interceptor = next_interceptor
199
+ end
200
+
201
+ # Called for every {Client.start_workflow} and {Client.execute_workflow} call.
202
+ #
203
+ # @param input [StartWorkflowInput] Input.
204
+ # @return [WorkflowHandle] Workflow handle.
205
+ def start_workflow(input)
206
+ next_interceptor.start_workflow(input)
207
+ end
208
+
209
+ # Called for every {Client.list_workflows} call.
210
+ #
211
+ # @param input [ListWorkflowsInput] Input.
212
+ # @return [Enumerator<WorkflowExecution>] Enumerable workflow executions.
213
+ def list_workflows(input)
214
+ next_interceptor.list_workflows(input)
215
+ end
216
+
217
+ # Called for every {Client.count_workflows} call.
218
+ #
219
+ # @param input [CountWorkflowsInput] Input.
220
+ # @return [WorkflowExecutionCount] Workflow count.
221
+ def count_workflows(input)
222
+ next_interceptor.count_workflows(input)
223
+ end
224
+
225
+ # Called for every {WorkflowHandle.describe} call.
226
+ #
227
+ # @param input [DescribeWorkflowInput] Input.
228
+ # @return [WorkflowExecution::Description] Workflow description.
229
+ def describe_workflow(input)
230
+ next_interceptor.describe_workflow(input)
231
+ end
232
+
233
+ # Called everytime the client needs workflow history. This includes getting the result.
234
+ #
235
+ # @param input [FetchWorkflowHistoryEventsInput] Input.
236
+ # @return [Enumerator<Api::History::V1::HistoryEvent>] Event enumerator.
237
+ def fetch_workflow_history_events(input)
238
+ next_interceptor.fetch_workflow_history_events(input)
239
+ end
240
+
241
+ # Called for every {WorkflowHandle.signal} call.
242
+ #
243
+ # @param input [SignalWorkflowInput] Input.
244
+ def signal_workflow(input)
245
+ next_interceptor.signal_workflow(input)
246
+ end
247
+
248
+ # Called for every {WorkflowHandle.query} call.
249
+ #
250
+ # @param input [QueryWorkflowInput] Input.
251
+ # @return [Object, nil] Query result.
252
+ def query_workflow(input)
253
+ next_interceptor.query_workflow(input)
254
+ end
255
+
256
+ # Called for every {WorkflowHandle.start_update} call.
257
+ #
258
+ # @param input [StartWorkflowUpdateInput] Input.
259
+ # @return [WorkflowUpdateHandle] Update handle.
260
+ def start_workflow_update(input)
261
+ next_interceptor.start_workflow_update(input)
262
+ end
263
+
264
+ # Called when polling for update result.
265
+ #
266
+ # @param input [PollWorkflowUpdateInput] Input.
267
+ # @return [Api::Update::V1::Outcome] Update outcome.
268
+ def poll_workflow_update(input)
269
+ next_interceptor.poll_workflow_update(input)
270
+ end
271
+
272
+ # Called for every {WorkflowHandle.cancel} call.
273
+ #
274
+ # @param input [CancelWorkflowInput] Input.
275
+ def cancel_workflow(input)
276
+ next_interceptor.cancel_workflow(input)
277
+ end
278
+
279
+ # Called for every {WorkflowHandle.terminate} call.
280
+ #
281
+ # @param input [TerminateWorkflowInput] Input.
282
+ def terminate_workflow(input)
283
+ next_interceptor.terminate_workflow(input)
284
+ end
285
+
286
+ # Called for every {AsyncActivityHandle.heartbeat} call.
287
+ #
288
+ # @param input [HeartbeatAsyncActivityInput] Input.
289
+ def heartbeat_async_activity(input)
290
+ next_interceptor.heartbeat_async_activity(input)
291
+ end
292
+
293
+ # Called for every {AsyncActivityHandle.complete} call.
294
+ #
295
+ # @param input [CompleteAsyncActivityInput] Input.
296
+ def complete_async_activity(input)
297
+ next_interceptor.complete_async_activity(input)
298
+ end
299
+
300
+ # Called for every {AsyncActivityHandle.fail} call.
301
+ #
302
+ # @param input [FailAsyncActivityInput] Input.
303
+ def fail_async_activity(input)
304
+ next_interceptor.fail_async_activity(input)
305
+ end
306
+
307
+ # Called for every {AsyncActivityHandle.report_cancellation} call.
308
+ #
309
+ # @param input [ReportCancellationAsyncActivityInput] Input.
310
+ def report_cancellation_async_activity(input)
311
+ next_interceptor.report_cancellation_async_activity(input)
312
+ end
313
+ end
314
+ end
315
+ end
316
+ end
@@ -0,0 +1,103 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'temporalio/api'
4
+ require 'temporalio/client/workflow_execution_status'
5
+ require 'temporalio/internal/proto_utils'
6
+ require 'temporalio/search_attributes'
7
+
8
+ module Temporalio
9
+ class Client
10
+ # Info for a single workflow execution run.
11
+ class WorkflowExecution
12
+ # @return [Api::Workflow::V1::WorkflowExecutionInfo] Underlying protobuf info.
13
+ attr_reader :raw_info
14
+
15
+ # @!visibility private
16
+ def initialize(raw_info, data_converter)
17
+ @raw_info = raw_info
18
+ @data_converter = data_converter
19
+ end
20
+
21
+ # @return [Time, nil] When the workflow was closed if closed.
22
+ def close_time
23
+ @raw_info.close_time&.to_time
24
+ end
25
+
26
+ # @return [Time, nil] When this workflow run started or should start.
27
+ def execution_time
28
+ @raw_info.execution_time&.to_time
29
+ end
30
+
31
+ # @return [Integer] Number of events in the history.
32
+ def history_length
33
+ @raw_info.history_length
34
+ end
35
+
36
+ # @return [String] ID for the workflow.
37
+ def id
38
+ @raw_info.execution.workflow_id
39
+ end
40
+
41
+ # @return [Hash<String, Object>, nil] Memo for the workflow.
42
+ def memo
43
+ @memo = Internal::ProtoUtils.memo_from_proto(@raw_info.memo, @data_converter) unless defined?(@memo)
44
+ @memo
45
+ end
46
+
47
+ # @return [String, nil] ID for the parent workflow if this was started as a child.
48
+ def parent_id
49
+ @raw_info.parent_execution&.workflow_id
50
+ end
51
+
52
+ # @return [String, nil] Run ID for the parent workflow if this was started as a child.
53
+ def parent_run_id
54
+ @raw_info.parent_execution&.run_id
55
+ end
56
+
57
+ # @return [String] Run ID for this workflow run.
58
+ def run_id
59
+ @raw_info.execution.run_id
60
+ end
61
+
62
+ # @return [SearchAttributes, nil] Current set of search attributes if any.
63
+ def search_attributes
64
+ unless defined?(@search_attributes)
65
+ @search_attributes = SearchAttributes.from_proto(@raw_info.search_attributes)
66
+ end
67
+ @search_attributes
68
+ end
69
+
70
+ # @return [Time] When the workflow was created.
71
+ def start_time
72
+ @raw_info.start_time.to_time
73
+ end
74
+
75
+ # @return [WorkflowExecutionStatus] Status for the workflow.
76
+ def status
77
+ Internal::ProtoUtils.enum_to_int(Api::Enums::V1::WorkflowExecutionStatus, @raw_info.status)
78
+ end
79
+
80
+ # @return [String] Task queue for the workflow.
81
+ def task_queue
82
+ @raw_info.task_queue
83
+ end
84
+
85
+ # @return [String] Type name for the workflow.
86
+ def workflow_type
87
+ @raw_info.type.name
88
+ end
89
+
90
+ # Description for a single workflow execution run.
91
+ class Description < WorkflowExecution
92
+ # @return [Api::WorkflowService::V1::DescribeWorkflowExecutionResponse] Underlying protobuf description.
93
+ attr_reader :raw_description
94
+
95
+ # @!visibility private
96
+ def initialize(raw_description, data_converter)
97
+ super(raw_description.workflow_execution_info, data_converter)
98
+ @raw_description = raw_description
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end