temporalio 1.11.0 → 1.12.0
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.
- checksums.yaml +4 -4
- data/Cargo.lock +33 -11
- data/Cargo.toml +1 -0
- data/README.md +168 -11
- data/ext/Cargo.toml +3 -3
- data/lib/temporalio/api/cloud/account/v1/message.rb +2 -1
- data/lib/temporalio/api/cloud/cloudservice/v1/request_response.rb +43 -1
- data/lib/temporalio/api/cloud/cloudservice/v1/service.rb +1 -1
- data/lib/temporalio/api/cloud/connectivityrule/v1/message.rb +1 -1
- data/lib/temporalio/api/cloud/identity/v1/message.rb +8 -1
- data/lib/temporalio/api/cloud/namespace/v1/message.rb +8 -1
- data/lib/temporalio/api/cloud/nexus/v1/message.rb +1 -1
- data/lib/temporalio/api/cloud/project/v1/message.rb +28 -0
- data/lib/temporalio/api/cloud/region/v1/message.rb +1 -1
- data/lib/temporalio/api/cloud/sink/v1/message.rb +2 -1
- data/lib/temporalio/api/enums/v1/failed_cause.rb +1 -1
- data/lib/temporalio/api/enums/v1/namespace.rb +2 -1
- data/lib/temporalio/api/operatorservice/v1/request_response.rb +9 -1
- data/lib/temporalio/api/operatorservice/v1/service.rb +1 -1
- data/lib/temporalio/api/payload_visitor.rb +66 -0
- data/lib/temporalio/api/taskqueue/v1/message.rb +3 -1
- data/lib/temporalio/api/workflowservice/v1/request_response.rb +2 -1
- data/lib/temporalio/api/workflowservice/v1/service.rb +1 -1
- data/lib/temporalio/client/connection/cloud_service.rb +285 -0
- data/lib/temporalio/client/connection/operator_service.rb +45 -0
- data/lib/temporalio/client/schedule.rb +56 -8
- data/lib/temporalio/contrib/aws/s3_driver/aws_sdk_s3_storage_driver_client.rb +0 -2
- data/lib/temporalio/contrib/aws/s3_driver/s3_storage_driver.rb +3 -5
- data/lib/temporalio/contrib/aws/s3_driver/s3_storage_driver_client.rb +0 -2
- data/lib/temporalio/contrib/aws/s3_driver.rb +0 -2
- data/lib/temporalio/converters/data_converter.rb +52 -1
- data/lib/temporalio/converters/external_storage.rb +6 -12
- data/lib/temporalio/converters/external_storage_concurrency.rb +4 -2
- data/lib/temporalio/converters/storage_driver.rb +3 -4
- data/lib/temporalio/converters/storage_driver_activity_info.rb +0 -2
- data/lib/temporalio/converters/storage_driver_claim.rb +0 -2
- data/lib/temporalio/converters/storage_driver_limiter.rb +16 -0
- data/lib/temporalio/converters/storage_driver_retrieve_context.rb +7 -6
- data/lib/temporalio/converters/storage_driver_select_context.rb +11 -5
- data/lib/temporalio/converters/storage_driver_store_context.rb +11 -7
- data/lib/temporalio/converters/storage_driver_workflow_info.rb +0 -2
- data/lib/temporalio/error.rb +10 -3
- data/lib/temporalio/internal/bridge/worker.rb +1 -0
- data/lib/temporalio/internal/client/described_schedule_action.rb +41 -0
- data/lib/temporalio/internal/client/implementation.rb +92 -48
- data/lib/temporalio/internal/external_storage_references.rb +5 -4
- data/lib/temporalio/internal/external_storage_runner.rb +177 -0
- data/lib/temporalio/internal/storage_operation_metrics.rb +76 -0
- data/lib/temporalio/internal/worker/activity_worker.rb +60 -24
- data/lib/temporalio/internal/worker/workflow_worker.rb +211 -15
- data/lib/temporalio/version.rb +1 -1
- data/lib/temporalio/worker/workflow_replayer.rb +5 -3
- data/lib/temporalio/worker.rb +4 -2
- data/rbi/temporalio/api/cloud/account/v1/message.rbi +84 -2
- data/rbi/temporalio/api/cloud/cloudservice/v1/request_response.rbi +5006 -1157
- data/rbi/temporalio/api/cloud/cloudservice/v1/service_services.rbi +171 -0
- data/rbi/temporalio/api/cloud/connectivityrule/v1/message.rbi +71 -16
- data/rbi/temporalio/api/cloud/identity/v1/message.rbi +789 -23
- data/rbi/temporalio/api/cloud/namespace/v1/message.rbi +765 -15
- data/rbi/temporalio/api/cloud/nexus/v1/message.rbi +19 -2
- data/rbi/temporalio/api/cloud/project/v1/message.rbi +334 -0
- data/rbi/temporalio/api/cloud/region/v1/message.rbi +1 -0
- data/rbi/temporalio/api/cloud/sink/v1/message.rbi +147 -0
- data/rbi/temporalio/api/common/v1/message.rbi +6 -0
- data/rbi/temporalio/api/enums/v1/failed_cause.rbi +2 -0
- data/rbi/temporalio/api/enums/v1/namespace.rbi +20 -0
- data/rbi/temporalio/api/history/v1/message.rbi +40 -18
- data/rbi/temporalio/api/operatorservice/v1/request_response.rbi +480 -0
- data/rbi/temporalio/api/operatorservice/v1/service_services.rbi +32 -0
- data/rbi/temporalio/api/payload_visitor.rbi +33 -0
- data/rbi/temporalio/api/schedule/v1/message.rbi +12 -6
- data/rbi/temporalio/api/taskqueue/v1/message.rbi +179 -13
- data/rbi/temporalio/api/worker/v1/message.rbi +6 -6
- data/rbi/temporalio/api/workflow/v1/message.rbi +12 -6
- data/rbi/temporalio/api/workflowservice/v1/request_response.rbi +140 -41
- data/rbi/temporalio/api/workflowservice/v1/service_services.rbi +3 -0
- data/rbi/temporalio/client/connection/cloud_service.rbi +57 -0
- data/rbi/temporalio/client/connection/operator_service.rbi +9 -0
- data/rbi/temporalio/converters/data_converter.rbi +43 -2
- data/rbi/temporalio/converters/external_storage.rbi +2 -7
- data/rbi/temporalio/converters/storage_driver_limiter.rbi +4 -0
- data/rbi/temporalio/converters/storage_driver_retrieve_context.rbi +1 -1
- data/rbi/temporalio/converters/storage_driver_select_context.rbi +6 -2
- data/rbi/temporalio/converters/storage_driver_store_context.rbi +6 -2
- data/rbi/temporalio/error.rbi +3 -1
- data/rbi/temporalio/internal/bridge/api/workflow_activation/workflow_activation.rbi +6 -0
- data/rbi/temporalio/internal/bridge/worker.rbi +4 -2
- data/rbi/temporalio/internal/client/described_schedule_action.rbi +22 -0
- data/rbi/temporalio/internal/client/implementation.rbi +30 -0
- data/rbi/temporalio/internal/external_storage_runner.rbi +36 -0
- data/rbi/temporalio/internal/storage_operation_metrics.rbi +27 -0
- data/rbi/temporalio/internal/worker/activity_worker.rbi +24 -4
- data/rbi/temporalio/internal/worker/workflow_worker.rbi +61 -1
- data/rbi/temporalio/workflow.rbi +0 -12
- data/sig/temporalio/api/cloud/account/v1/message.rbs +30 -0
- data/sig/temporalio/api/cloud/cloudservice/v1/request_response.rbs +2122 -601
- data/sig/temporalio/api/cloud/connectivityrule/v1/message.rbs +29 -4
- data/sig/temporalio/api/cloud/identity/v1/message.rbs +342 -1
- data/sig/temporalio/api/cloud/namespace/v1/message.rbs +341 -2
- data/sig/temporalio/api/cloud/nexus/v1/message.rbs +9 -0
- data/sig/temporalio/api/cloud/project/v1/message.rbs +164 -0
- data/sig/temporalio/api/cloud/region/v1/message.rbs +5 -3
- data/sig/temporalio/api/cloud/sink/v1/message.rbs +66 -0
- data/sig/temporalio/api/common/v1/message.rbs +6 -0
- data/sig/temporalio/api/enums/v1/event_type.rbs +1 -0
- data/sig/temporalio/api/enums/v1/failed_cause.rbs +9 -3
- data/sig/temporalio/api/enums/v1/namespace.rbs +30 -2
- data/sig/temporalio/api/enums/v1/time_skipping.rbs +1 -0
- data/sig/temporalio/api/history/v1/message.rbs +8 -0
- data/sig/temporalio/api/operatorservice/v1/request_response.rbs +188 -0
- data/sig/temporalio/api/payload_visitor.rbs +11 -0
- data/sig/temporalio/api/schedule/v1/message.rbs +2 -0
- data/sig/temporalio/api/taskqueue/v1/message.rbs +66 -5
- data/sig/temporalio/api/worker/v1/message.rbs +2 -2
- data/sig/temporalio/api/workflow/v1/message.rbs +2 -0
- data/sig/temporalio/api/workflowservice/v1/request_response.rbs +53 -9
- data/sig/temporalio/client/connection/cloud_service.rbs +76 -0
- data/sig/temporalio/client/connection/operator_service.rbs +12 -0
- data/sig/temporalio/client/schedule.rbs +24 -3
- data/sig/temporalio/contrib/aws/s3_driver/s3_storage_driver.rbs +2 -1
- data/sig/temporalio/contrib/open_telemetry.rbs +4 -4
- data/sig/temporalio/converters/data_converter.rbs +19 -1
- data/sig/temporalio/converters/external_storage.rbs +1 -3
- data/sig/temporalio/converters/storage_driver_limiter.rbs +5 -0
- data/sig/temporalio/converters/storage_driver_retrieve_context.rbs +1 -1
- data/sig/temporalio/converters/storage_driver_select_context.rbs +3 -1
- data/sig/temporalio/converters/storage_driver_store_context.rbs +3 -1
- data/sig/temporalio/error.rbs +4 -1
- data/sig/temporalio/internal/bridge/api/workflow_activation/workflow_activation.rbs +4 -0
- data/sig/temporalio/internal/bridge/worker.rbs +2 -0
- data/sig/temporalio/internal/client/described_schedule_action.rbs +18 -0
- data/sig/temporalio/internal/client/implementation.rbs +22 -0
- data/sig/temporalio/internal/external_storage_runner.rbs +32 -0
- data/sig/temporalio/internal/storage_operation_metrics.rbs +25 -0
- data/sig/temporalio/internal/worker/activity_worker.rbs +11 -2
- data/sig/temporalio/internal/worker/workflow_worker.rbs +32 -1
- metadata +13 -2
- data/sig/open_telemetry.rbs +0 -47
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'temporalio/internal/bridge/api'
|
|
4
|
+
require 'temporalio/internal/proto_utils'
|
|
5
|
+
|
|
6
|
+
module Temporalio
|
|
7
|
+
module Internal
|
|
8
|
+
# Gathers what external storage moved during one store or retrieve pass, for core to report on the activation
|
|
9
|
+
# completion.
|
|
10
|
+
#
|
|
11
|
+
# @!visibility private
|
|
12
|
+
class StorageOperationMetrics
|
|
13
|
+
def initialize
|
|
14
|
+
@mutex = Mutex.new
|
|
15
|
+
@payload_count = 0
|
|
16
|
+
@total_size_bytes = 0
|
|
17
|
+
@driver_names = Set.new
|
|
18
|
+
@spans = []
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Record one driver call that moved payloads.
|
|
22
|
+
#
|
|
23
|
+
# @param driver_name [String] Driver that stored or retrieved the payloads.
|
|
24
|
+
# @param payload_count [Integer] Number of payloads moved.
|
|
25
|
+
# @param total_size_bytes [Integer] Encoded size of the payloads moved.
|
|
26
|
+
# @param start_time [Float] Monotonic clock reading taken before the driver call.
|
|
27
|
+
# @param end_time [Float] Monotonic clock reading taken after the driver call.
|
|
28
|
+
def record(driver_name:, payload_count:, total_size_bytes:, start_time:, end_time:)
|
|
29
|
+
@mutex.synchronize do
|
|
30
|
+
@driver_names << driver_name
|
|
31
|
+
@payload_count += payload_count
|
|
32
|
+
@total_size_bytes += total_size_bytes
|
|
33
|
+
@spans << [start_time, end_time]
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# @return [Bridge::Api::Common::ExternalStorageMetrics, nil] Metrics for the pass, or nil when it moved nothing,
|
|
38
|
+
# so the completion field stays unset.
|
|
39
|
+
def to_proto
|
|
40
|
+
payload_count, total_size_bytes, duration_seconds, driver_names = @mutex.synchronize do
|
|
41
|
+
return nil if @payload_count.zero?
|
|
42
|
+
|
|
43
|
+
[@payload_count, @total_size_bytes, union_seconds, @driver_names.sort]
|
|
44
|
+
end
|
|
45
|
+
# Built outside the lock, since creating a protobuf message takes a process-wide lock that would otherwise also
|
|
46
|
+
# hold up record
|
|
47
|
+
Bridge::Api::Common::ExternalStorageMetrics.new(
|
|
48
|
+
payload_count:,
|
|
49
|
+
total_size_bytes:,
|
|
50
|
+
total_duration: ProtoUtils.seconds_to_duration(duration_seconds),
|
|
51
|
+
driver_names:
|
|
52
|
+
)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
private
|
|
56
|
+
|
|
57
|
+
def union_seconds
|
|
58
|
+
first, *rest = @spans.sort
|
|
59
|
+
return 0.0 unless first
|
|
60
|
+
|
|
61
|
+
total = 0.0
|
|
62
|
+
span_start, span_end = first
|
|
63
|
+
rest.each do |start_time, end_time|
|
|
64
|
+
if start_time > span_end
|
|
65
|
+
total += span_end - span_start
|
|
66
|
+
span_start = start_time
|
|
67
|
+
span_end = end_time
|
|
68
|
+
elsif end_time > span_end
|
|
69
|
+
span_end = end_time
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
total + (span_end - span_start)
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
@@ -4,7 +4,10 @@ require 'temporalio/activity'
|
|
|
4
4
|
require 'temporalio/activity/definition'
|
|
5
5
|
require 'temporalio/cancellation'
|
|
6
6
|
require 'temporalio/converters/raw_value'
|
|
7
|
+
require 'temporalio/converters/storage_driver_activity_info'
|
|
8
|
+
require 'temporalio/converters/storage_driver_workflow_info'
|
|
7
9
|
require 'temporalio/internal/bridge/api'
|
|
10
|
+
require 'temporalio/internal/external_storage_runner'
|
|
8
11
|
require 'temporalio/internal/proto_utils'
|
|
9
12
|
require 'temporalio/scoped_logger'
|
|
10
13
|
require 'temporalio/worker/interceptor'
|
|
@@ -23,6 +26,7 @@ module Temporalio
|
|
|
23
26
|
@worker = worker
|
|
24
27
|
@bridge_worker = bridge_worker
|
|
25
28
|
@runtime_metric_meter = worker.options.client.connection.options.runtime.metric_meter
|
|
29
|
+
@data_converter_without_storage = worker.options.client.data_converter._without_storage
|
|
26
30
|
|
|
27
31
|
# Create shared logger that gives scoped activity details
|
|
28
32
|
@scoped_logger = ScopedLogger.new(@worker.options.logger)
|
|
@@ -131,7 +135,7 @@ module Temporalio
|
|
|
131
135
|
failed: Bridge::Api::ActivityResult::Failure.new(
|
|
132
136
|
# TODO(cretz): If failure conversion does slow failure
|
|
133
137
|
# encoding, it can gum up the system
|
|
134
|
-
failure:
|
|
138
|
+
failure: storage_data_converter(start).to_failure(e)
|
|
135
139
|
)
|
|
136
140
|
)
|
|
137
141
|
)
|
|
@@ -191,7 +195,9 @@ module Temporalio
|
|
|
191
195
|
priority: Priority._from_proto(start.priority),
|
|
192
196
|
raw_heartbeat_details: begin
|
|
193
197
|
payloads = start.heartbeat_details.to_ary
|
|
194
|
-
|
|
198
|
+
data_converter = @worker.options.client.data_converter
|
|
199
|
+
payloads = ExternalStorageRunner.new(data_converter.external_storage, namespace: nil).retrieve(payloads)
|
|
200
|
+
codec = data_converter.payload_codec
|
|
195
201
|
payloads = codec.decode(payloads) if codec
|
|
196
202
|
payloads.map { |p| Temporalio::Converters::RawValue.new(p) }
|
|
197
203
|
end,
|
|
@@ -214,7 +220,10 @@ module Temporalio
|
|
|
214
220
|
# If the activity wants raw_args, we only decode we don't convert
|
|
215
221
|
args: if defn.raw_args
|
|
216
222
|
payloads = start.input.to_ary
|
|
217
|
-
|
|
223
|
+
data_converter = @worker.options.client.data_converter
|
|
224
|
+
payloads = ExternalStorageRunner.new(data_converter.external_storage, namespace: nil)
|
|
225
|
+
.retrieve(payloads)
|
|
226
|
+
codec = data_converter.payload_codec
|
|
218
227
|
payloads = codec.decode(payloads) if codec
|
|
219
228
|
payloads.map { |p| Temporalio::Converters::RawValue.new(p) }
|
|
220
229
|
else
|
|
@@ -240,7 +249,7 @@ module Temporalio
|
|
|
240
249
|
)
|
|
241
250
|
Activity::Context._current_executor&.set_activity_context(defn, activity)
|
|
242
251
|
set_running_activity(task_token, activity)
|
|
243
|
-
run_activity(defn, activity, input)
|
|
252
|
+
run_activity(defn, activity, input, storage_data_converter(start))
|
|
244
253
|
rescue Exception => e # rubocop:disable Lint/RescueException -- We are intending to catch everything here
|
|
245
254
|
@scoped_logger.warn("Failed starting or sending completion for activity #{start.activity_type}")
|
|
246
255
|
@scoped_logger.warn(e)
|
|
@@ -250,11 +259,7 @@ module Temporalio
|
|
|
250
259
|
@bridge_worker.complete_activity_task(
|
|
251
260
|
Bridge::Api::CoreInterface::ActivityTaskCompletion.new(
|
|
252
261
|
task_token:,
|
|
253
|
-
result:
|
|
254
|
-
failed: Bridge::Api::ActivityResult::Failure.new(
|
|
255
|
-
failure: @worker.options.client.data_converter.to_failure(e)
|
|
256
|
-
)
|
|
257
|
-
)
|
|
262
|
+
result: failed_result(e, storage_data_converter(start))
|
|
258
263
|
)
|
|
259
264
|
)
|
|
260
265
|
rescue StandardError => e_inner
|
|
@@ -266,7 +271,7 @@ module Temporalio
|
|
|
266
271
|
remove_running_activity(task_token)
|
|
267
272
|
end
|
|
268
273
|
|
|
269
|
-
def run_activity(defn, activity, input)
|
|
274
|
+
def run_activity(defn, activity, input, data_converter)
|
|
270
275
|
result = begin
|
|
271
276
|
# Create the instance. We choose to do this before interceptors so that it is available in the interceptor.
|
|
272
277
|
activity.instance = defn.instance.is_a?(Proc) ? defn.instance.call : defn.instance # steep:ignore
|
|
@@ -277,7 +282,7 @@ module Temporalio
|
|
|
277
282
|
impl = @worker._activity_interceptors.reverse_each.reduce(impl) do |acc, int|
|
|
278
283
|
int.intercept_activity(acc)
|
|
279
284
|
end
|
|
280
|
-
impl.init(OutboundImplementation.new(self, activity.info.task_token))
|
|
285
|
+
impl.init(OutboundImplementation.new(self, activity.info.task_token, data_converter))
|
|
281
286
|
|
|
282
287
|
# Execute
|
|
283
288
|
result = impl.execute(input)
|
|
@@ -285,7 +290,7 @@ module Temporalio
|
|
|
285
290
|
# Success
|
|
286
291
|
Bridge::Api::ActivityResult::ActivityExecutionResult.new(
|
|
287
292
|
completed: Bridge::Api::ActivityResult::Success.new(
|
|
288
|
-
result:
|
|
293
|
+
result: data_converter.to_payload(result, hint: input.result_hint)
|
|
289
294
|
)
|
|
290
295
|
)
|
|
291
296
|
rescue Exception => e # rubocop:disable Lint/RescueException -- We are intending to catch everything here
|
|
@@ -300,7 +305,7 @@ module Temporalio
|
|
|
300
305
|
@scoped_logger.debug('Completing activity as failed due to exception caused by pause')
|
|
301
306
|
Bridge::Api::ActivityResult::ActivityExecutionResult.new(
|
|
302
307
|
failed: Bridge::Api::ActivityResult::Failure.new(
|
|
303
|
-
failure:
|
|
308
|
+
failure: data_converter.to_failure(
|
|
304
309
|
Error._with_backtrace_and_cause(
|
|
305
310
|
Error::ApplicationError.new('Activity paused', type: 'ActivityPause'), backtrace: nil, cause: e
|
|
306
311
|
)
|
|
@@ -312,7 +317,7 @@ module Temporalio
|
|
|
312
317
|
@scoped_logger.debug('Completing activity as failed due to exception caused by reset')
|
|
313
318
|
Bridge::Api::ActivityResult::ActivityExecutionResult.new(
|
|
314
319
|
failed: Bridge::Api::ActivityResult::Failure.new(
|
|
315
|
-
failure:
|
|
320
|
+
failure: data_converter.to_failure(
|
|
316
321
|
Error._with_backtrace_and_cause(
|
|
317
322
|
Error::ApplicationError.new('Activity reset', type: 'ActivityReset'), backtrace: nil, cause: e
|
|
318
323
|
)
|
|
@@ -324,7 +329,7 @@ module Temporalio
|
|
|
324
329
|
@scoped_logger.debug('Completing activity as canceled')
|
|
325
330
|
Bridge::Api::ActivityResult::ActivityExecutionResult.new(
|
|
326
331
|
cancelled: Bridge::Api::ActivityResult::Cancellation.new(
|
|
327
|
-
failure:
|
|
332
|
+
failure: data_converter.to_failure(e)
|
|
328
333
|
)
|
|
329
334
|
)
|
|
330
335
|
else
|
|
@@ -336,11 +341,7 @@ module Temporalio
|
|
|
336
341
|
end
|
|
337
342
|
@scoped_logger.add(log_level, 'Completing activity as failed')
|
|
338
343
|
@scoped_logger.add(log_level, e)
|
|
339
|
-
|
|
340
|
-
failed: Bridge::Api::ActivityResult::Failure.new(
|
|
341
|
-
failure: @worker.options.client.data_converter.to_failure(e)
|
|
342
|
-
)
|
|
343
|
-
)
|
|
344
|
+
failed_result(e, data_converter)
|
|
344
345
|
end
|
|
345
346
|
end
|
|
346
347
|
|
|
@@ -353,6 +354,42 @@ module Temporalio
|
|
|
353
354
|
)
|
|
354
355
|
end
|
|
355
356
|
|
|
357
|
+
def failed_result(error, data_converter)
|
|
358
|
+
if error.is_a?(Error::ExternalStorageError)
|
|
359
|
+
Bridge::Api::ActivityResult::ActivityExecutionResult.new(
|
|
360
|
+
failed: Bridge::Api::ActivityResult::Failure.new(
|
|
361
|
+
failure: @data_converter_without_storage.to_failure(error),
|
|
362
|
+
cause: :ACTIVITY_TASK_FAILED_CAUSE_EXTERNAL_STORAGE_FAILURE
|
|
363
|
+
)
|
|
364
|
+
)
|
|
365
|
+
else
|
|
366
|
+
Bridge::Api::ActivityResult::ActivityExecutionResult.new(
|
|
367
|
+
failed: Bridge::Api::ActivityResult::Failure.new(failure: data_converter.to_failure(error))
|
|
368
|
+
)
|
|
369
|
+
end
|
|
370
|
+
end
|
|
371
|
+
|
|
372
|
+
def storage_data_converter(start)
|
|
373
|
+
@worker.options.client.data_converter._with_storage_target(
|
|
374
|
+
namespace: @worker.options.client.namespace, target: storage_target_for_task(start)
|
|
375
|
+
)
|
|
376
|
+
end
|
|
377
|
+
|
|
378
|
+
def storage_target_for_task(start)
|
|
379
|
+
namespace = ProtoUtils.string_or(start.workflow_namespace, @worker.options.client.namespace)
|
|
380
|
+
scheduling_workflow_id = ProtoUtils.string_or(start.workflow_execution&.workflow_id)
|
|
381
|
+
if scheduling_workflow_id
|
|
382
|
+
Converters::StorageDriverWorkflowInfo.new(
|
|
383
|
+
namespace:, id: scheduling_workflow_id, run_id: ProtoUtils.string_or(start.workflow_execution&.run_id),
|
|
384
|
+
type: ProtoUtils.string_or(start.workflow_type)
|
|
385
|
+
)
|
|
386
|
+
else
|
|
387
|
+
Converters::StorageDriverActivityInfo.new(
|
|
388
|
+
namespace:, id: start.activity_id, run_id: ProtoUtils.string_or(start.run_id), type: start.activity_type
|
|
389
|
+
)
|
|
390
|
+
end
|
|
391
|
+
end
|
|
392
|
+
|
|
356
393
|
def assert_valid_activity(activity)
|
|
357
394
|
defn = @activities[activity]
|
|
358
395
|
defn = @activities[nil] if !defn && !Internal::ProtoUtils.reserved_name?(activity)
|
|
@@ -446,19 +483,18 @@ module Temporalio
|
|
|
446
483
|
end
|
|
447
484
|
|
|
448
485
|
class OutboundImplementation < Temporalio::Worker::Interceptor::Activity::Outbound
|
|
449
|
-
def initialize(worker, task_token)
|
|
486
|
+
def initialize(worker, task_token, data_converter)
|
|
450
487
|
super(nil) # steep:ignore
|
|
451
488
|
@worker = worker
|
|
452
489
|
@task_token = task_token
|
|
490
|
+
@data_converter = data_converter
|
|
453
491
|
end
|
|
454
492
|
|
|
455
493
|
def heartbeat(input)
|
|
456
494
|
@worker.bridge_worker.record_activity_heartbeat(
|
|
457
495
|
Bridge::Api::CoreInterface::ActivityHeartbeat.new(
|
|
458
496
|
task_token: @task_token,
|
|
459
|
-
details: ProtoUtils.convert_to_payload_array(@
|
|
460
|
-
input.details,
|
|
461
|
-
hints: input.detail_hints)
|
|
497
|
+
details: ProtoUtils.convert_to_payload_array(@data_converter, input.details, hints: input.detail_hints)
|
|
462
498
|
).to_proto
|
|
463
499
|
)
|
|
464
500
|
end
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require 'temporalio/api/payload_visitor'
|
|
4
|
+
require 'temporalio/converters/storage_driver_workflow_info'
|
|
4
5
|
require 'temporalio/error'
|
|
6
|
+
require 'temporalio/internal/bridge/api'
|
|
7
|
+
require 'temporalio/internal/external_storage_runner'
|
|
8
|
+
require 'temporalio/internal/proto_utils'
|
|
9
|
+
require 'temporalio/internal/storage_operation_metrics'
|
|
5
10
|
require 'temporalio/internal/worker/workflow_instance'
|
|
6
11
|
require 'temporalio/scoped_logger'
|
|
7
12
|
require 'temporalio/workflow'
|
|
@@ -81,18 +86,34 @@ module Temporalio
|
|
|
81
86
|
@executor = workflow_executor
|
|
82
87
|
|
|
83
88
|
payload_codec = data_converter.payload_codec
|
|
89
|
+
external_storage = data_converter.external_storage
|
|
84
90
|
@workflow_payload_codec_thread_pool = workflow_payload_codec_thread_pool
|
|
85
|
-
if !Fiber.current_scheduler && payload_codec && !@workflow_payload_codec_thread_pool
|
|
86
|
-
raise ArgumentError, 'Must have workflow payload codec thread pool if providing codec
|
|
91
|
+
if !Fiber.current_scheduler && (payload_codec || external_storage) && !@workflow_payload_codec_thread_pool
|
|
92
|
+
raise ArgumentError, 'Must have workflow payload codec thread pool if providing codec or external ' \
|
|
93
|
+
'storage and not using fibers'
|
|
87
94
|
end
|
|
88
95
|
|
|
89
|
-
# If there is a payload codec
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
+
# If there is a payload codec or external storage, payloads are encoded and decoded by visitors built per
|
|
97
|
+
# pass, so each pass can measure its own storage operations. Storage comes after the codec when encoding and
|
|
98
|
+
# before it when decoding. These may block, so they run in the background.
|
|
99
|
+
@payload_codec = payload_codec
|
|
100
|
+
@external_storage = external_storage
|
|
101
|
+
@storage_runner = ExternalStorageRunner.new(external_storage, namespace:)
|
|
102
|
+
@decode_in_background = !payload_codec.nil? || !external_storage.nil?
|
|
103
|
+
# Download metrics by run ID, waiting for the completion of the activation that measured them. Core never has
|
|
104
|
+
# two activations of one run outstanding, so the run ID identifies the activation.
|
|
105
|
+
@pending_download_metrics = {}
|
|
106
|
+
@pending_download_metrics_mutex = Mutex.new
|
|
107
|
+
@pending_initial_targets = {}
|
|
108
|
+
@pending_initial_targets_mutex = Mutex.new
|
|
109
|
+
unless @decode_in_background
|
|
110
|
+
# Without a codec or storage, decoding only rejects references that were never retrieved. That needs no
|
|
111
|
+
# I/O, so it runs inline and existing workers need no thread pool.
|
|
112
|
+
storage_runner = @storage_runner
|
|
113
|
+
@payload_rejecting_visitor = Api::PayloadVisitor.new(skip_search_attributes: true) do |payload_or_payloads|
|
|
114
|
+
storage_runner.retrieve(
|
|
115
|
+
payload_or_payloads.is_a?(Api::Common::V1::Payload) ? [payload_or_payloads] : payload_or_payloads.to_a
|
|
116
|
+
)
|
|
96
117
|
end
|
|
97
118
|
end
|
|
98
119
|
|
|
@@ -129,8 +150,10 @@ module Temporalio
|
|
|
129
150
|
end
|
|
130
151
|
|
|
131
152
|
def handle_activation(runner:, activation:, decoded:)
|
|
132
|
-
|
|
133
|
-
|
|
153
|
+
if !decoded && !@decode_in_background
|
|
154
|
+
decode_activation(runner, activation)
|
|
155
|
+
# Decode in background if not decoded but it needs to be
|
|
156
|
+
elsif !decoded
|
|
134
157
|
if Fiber.current_scheduler
|
|
135
158
|
Fiber.schedule { decode_activation(runner, activation) }
|
|
136
159
|
else
|
|
@@ -150,7 +173,7 @@ module Temporalio
|
|
|
150
173
|
# Returns whether completion was submitted to the bridge
|
|
151
174
|
# rubocop:disable-next Naming/PredicateMethod
|
|
152
175
|
def handle_activation_complete(runner:, activation_completion:, encoded:, completion_complete_queue:)
|
|
153
|
-
if @
|
|
176
|
+
if @decode_in_background && !encoded
|
|
154
177
|
if Fiber.current_scheduler
|
|
155
178
|
Fiber.schedule { encode_activation_completion(runner, activation_completion) }
|
|
156
179
|
else
|
|
@@ -173,22 +196,191 @@ module Temporalio
|
|
|
173
196
|
|
|
174
197
|
private
|
|
175
198
|
|
|
199
|
+
# Decoding and encoding run in a thread pool that only warns about errors, so a failure must complete the
|
|
200
|
+
# activation as failed. Otherwise the run waits forever for a completion that never comes.
|
|
201
|
+
|
|
176
202
|
def decode_activation(runner, activation)
|
|
177
|
-
@
|
|
203
|
+
if @decode_in_background
|
|
204
|
+
metrics = nil
|
|
205
|
+
if @external_storage
|
|
206
|
+
metrics = StorageOperationMetrics.new
|
|
207
|
+
# Stored before the visit, so the completion reports what was retrieved even if decoding then fails
|
|
208
|
+
@pending_download_metrics_mutex.synchronize { @pending_download_metrics[activation.run_id] = metrics }
|
|
209
|
+
remember_initial_target(activation)
|
|
210
|
+
end
|
|
211
|
+
payload_decoding_visitor(metrics).run(activation)
|
|
212
|
+
else
|
|
213
|
+
@payload_rejecting_visitor&.run(activation)
|
|
214
|
+
end
|
|
178
215
|
runner.apply_workflow_activation_decoded(workflow_worker: self, activation:)
|
|
216
|
+
rescue Exception => e # rubocop:disable Lint/RescueException
|
|
217
|
+
activation_completion = WorkflowInstance.new_completion_with_failure(
|
|
218
|
+
run_id: activation.run_id,
|
|
219
|
+
error: e,
|
|
220
|
+
failure_converter: @state.data_converter.failure_converter,
|
|
221
|
+
payload_converter: @state.data_converter.payload_converter
|
|
222
|
+
)
|
|
223
|
+
activation_completion.failed.force_cause = task_failed_cause(e)
|
|
224
|
+
# Not yet encoded, so the failure goes through the codec and storage like any other completion
|
|
225
|
+
runner.apply_workflow_activation_complete(workflow_worker: self, activation_completion:, encoded: false)
|
|
179
226
|
end
|
|
180
227
|
|
|
181
228
|
def encode_activation_completion(runner, activation_completion)
|
|
182
|
-
@
|
|
229
|
+
download_metrics = @pending_download_metrics_mutex.synchronize do
|
|
230
|
+
@pending_download_metrics.delete(activation_completion.run_id)
|
|
231
|
+
end
|
|
232
|
+
initial_target = @pending_initial_targets_mutex.synchronize do
|
|
233
|
+
@pending_initial_targets.delete(activation_completion.run_id)
|
|
234
|
+
end
|
|
235
|
+
upload_metrics = StorageOperationMetrics.new if @external_storage
|
|
236
|
+
begin
|
|
237
|
+
encode_completion_payloads(activation_completion, upload_metrics, initial_target)
|
|
238
|
+
rescue Exception => e # rubocop:disable Lint/RescueException
|
|
239
|
+
# Only the message is sent, and it is marked encoded, because encoding a failure that carries payloads
|
|
240
|
+
# could fail the same way and retry forever
|
|
241
|
+
activation_completion = Bridge::Api::WorkflowCompletion::WorkflowActivationCompletion.new(
|
|
242
|
+
run_id: activation_completion.run_id,
|
|
243
|
+
failed: Bridge::Api::WorkflowCompletion::Failure.new(
|
|
244
|
+
failure: Api::Failure::V1::Failure.new(message: "Failed encoding completion: #{e.message}"),
|
|
245
|
+
force_cause: encoding_failure_cause(e, activation_completion)
|
|
246
|
+
)
|
|
247
|
+
)
|
|
248
|
+
end
|
|
249
|
+
# Reported even when a pass failed, since what it moved before failing still took time
|
|
250
|
+
activation_completion.payload_download_metrics = download_metrics&.to_proto
|
|
251
|
+
activation_completion.payload_upload_metrics = upload_metrics&.to_proto
|
|
183
252
|
runner.apply_workflow_activation_complete(workflow_worker: self, activation_completion:, encoded: true)
|
|
184
253
|
end
|
|
185
254
|
|
|
186
|
-
def
|
|
255
|
+
def task_failed_cause(error)
|
|
256
|
+
if error.is_a?(Error::ExternalStorageError)
|
|
257
|
+
:WORKFLOW_TASK_FAILED_CAUSE_EXTERNAL_STORAGE_FAILURE
|
|
258
|
+
else
|
|
259
|
+
:WORKFLOW_TASK_FAILED_CAUSE_UNSPECIFIED
|
|
260
|
+
end
|
|
261
|
+
end
|
|
262
|
+
|
|
263
|
+
def encoding_failure_cause(encoding_error, activation_completion)
|
|
264
|
+
if encoding_error.is_a?(Error::ExternalStorageError)
|
|
265
|
+
:WORKFLOW_TASK_FAILED_CAUSE_EXTERNAL_STORAGE_FAILURE
|
|
266
|
+
else
|
|
267
|
+
activation_completion.failed&.force_cause || :WORKFLOW_TASK_FAILED_CAUSE_UNSPECIFIED
|
|
268
|
+
end
|
|
269
|
+
end
|
|
270
|
+
|
|
271
|
+
def remember_initial_target(activation)
|
|
272
|
+
initialize_job = activation.jobs.find { |job| !job.initialize_workflow.nil? }&.initialize_workflow
|
|
273
|
+
return unless initialize_job
|
|
274
|
+
|
|
275
|
+
initial_target = Converters::StorageDriverWorkflowInfo.new(
|
|
276
|
+
namespace: @state.namespace, id: initialize_job.workflow_id, run_id: activation.run_id,
|
|
277
|
+
type: initialize_job.workflow_type
|
|
278
|
+
)
|
|
279
|
+
@pending_initial_targets_mutex.synchronize { @pending_initial_targets[activation.run_id] = initial_target }
|
|
280
|
+
end
|
|
281
|
+
|
|
282
|
+
def encode_completion_payloads(activation_completion, metrics, initial_target)
|
|
283
|
+
workflow_info = @state.running_workflow_info(activation_completion.run_id)
|
|
284
|
+
current_workflow_target = workflow_info ? storage_target_for_workflow(workflow_info) : initial_target
|
|
285
|
+
if activation_completion.has_successful?
|
|
286
|
+
activation_completion.successful.commands.each do |command|
|
|
287
|
+
command_target = storage_target_for_command(command, workflow_info, current_workflow_target)
|
|
288
|
+
payload_encoding_visitor(metrics, command_target).run(command)
|
|
289
|
+
end
|
|
290
|
+
end
|
|
291
|
+
return unless activation_completion.has_failed?
|
|
292
|
+
|
|
293
|
+
payload_encoding_visitor(metrics, current_workflow_target).run(activation_completion.failed)
|
|
294
|
+
end
|
|
295
|
+
|
|
296
|
+
def storage_target_for_workflow(workflow_info)
|
|
297
|
+
Converters::StorageDriverWorkflowInfo.new(
|
|
298
|
+
namespace: workflow_info.namespace, id: workflow_info.workflow_id, run_id: workflow_info.run_id,
|
|
299
|
+
type: workflow_info.workflow_type
|
|
300
|
+
)
|
|
301
|
+
end
|
|
302
|
+
|
|
303
|
+
def storage_target_for_command(command, workflow_info, current_workflow_target)
|
|
304
|
+
return current_workflow_target unless workflow_info
|
|
305
|
+
|
|
306
|
+
case command.variant
|
|
307
|
+
when :start_child_workflow_execution
|
|
308
|
+
child = command.start_child_workflow_execution
|
|
309
|
+
Converters::StorageDriverWorkflowInfo.new(
|
|
310
|
+
namespace: ProtoUtils.string_or(child.namespace, workflow_info.namespace), id: child.workflow_id,
|
|
311
|
+
type: child.workflow_type
|
|
312
|
+
)
|
|
313
|
+
when :signal_external_workflow_execution
|
|
314
|
+
storage_target_for_signaled_workflow(command.signal_external_workflow_execution, workflow_info)
|
|
315
|
+
when :continue_as_new_workflow_execution
|
|
316
|
+
Converters::StorageDriverWorkflowInfo.new(
|
|
317
|
+
namespace: workflow_info.namespace, id: workflow_info.workflow_id,
|
|
318
|
+
type: ProtoUtils.string_or(
|
|
319
|
+
command.continue_as_new_workflow_execution.workflow_type, workflow_info.workflow_type
|
|
320
|
+
)
|
|
321
|
+
)
|
|
322
|
+
when :complete_workflow_execution
|
|
323
|
+
storage_target_for_result(workflow_info, current_workflow_target)
|
|
324
|
+
else
|
|
325
|
+
current_workflow_target
|
|
326
|
+
end
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
def storage_target_for_signaled_workflow(signal, workflow_info)
|
|
330
|
+
case signal.target
|
|
331
|
+
when :workflow_execution
|
|
332
|
+
execution = signal.workflow_execution
|
|
333
|
+
Converters::StorageDriverWorkflowInfo.new(
|
|
334
|
+
namespace: ProtoUtils.string_or(execution.namespace, workflow_info.namespace), id: execution.workflow_id,
|
|
335
|
+
run_id: ProtoUtils.string_or(execution.run_id)
|
|
336
|
+
)
|
|
337
|
+
when :child_workflow_id
|
|
338
|
+
Converters::StorageDriverWorkflowInfo.new(namespace: workflow_info.namespace, id: signal.child_workflow_id)
|
|
339
|
+
end
|
|
340
|
+
end
|
|
341
|
+
|
|
342
|
+
def storage_target_for_result(workflow_info, current_workflow_target)
|
|
343
|
+
parent = workflow_info.parent
|
|
344
|
+
return current_workflow_target if parent.nil? || workflow_info.continued_run_id
|
|
345
|
+
|
|
346
|
+
Converters::StorageDriverWorkflowInfo.new(
|
|
347
|
+
namespace: parent.namespace, id: parent.workflow_id, run_id: parent.run_id
|
|
348
|
+
)
|
|
349
|
+
end
|
|
350
|
+
|
|
351
|
+
def payload_encoding_visitor(metrics, target)
|
|
352
|
+
payload_codec = @payload_codec
|
|
353
|
+
external_storage = @external_storage
|
|
354
|
+
storage_runner = @storage_runner
|
|
355
|
+
Api::PayloadVisitor.new(skip_search_attributes: true) do |payload_or_payloads|
|
|
356
|
+
replace_payloads_on_visit(payload_or_payloads) do |payloads|
|
|
357
|
+
payloads = payload_codec.encode(payloads) if payload_codec
|
|
358
|
+
payloads = storage_runner.store(payloads.to_a, target:, metrics:) if external_storage
|
|
359
|
+
payloads
|
|
360
|
+
end
|
|
361
|
+
end
|
|
362
|
+
end
|
|
363
|
+
|
|
364
|
+
def payload_decoding_visitor(metrics)
|
|
365
|
+
payload_codec = @payload_codec
|
|
366
|
+
storage_runner = @storage_runner
|
|
367
|
+
Api::PayloadVisitor.new(skip_search_attributes: true) do |payload_or_payloads|
|
|
368
|
+
replace_payloads_on_visit(payload_or_payloads) do |payloads|
|
|
369
|
+
payloads = storage_runner.retrieve(payloads.to_a, metrics:)
|
|
370
|
+
payloads = payload_codec.decode(payloads) if payload_codec
|
|
371
|
+
payloads
|
|
372
|
+
end
|
|
373
|
+
end
|
|
374
|
+
end
|
|
375
|
+
|
|
376
|
+
def replace_payloads_on_visit(payload_or_payloads, &)
|
|
187
377
|
case payload_or_payloads
|
|
188
378
|
when Temporalio::Api::Common::V1::Payload
|
|
189
379
|
new_payloads = yield [payload_or_payloads]
|
|
190
380
|
payload_or_payloads.metadata = new_payloads.first.metadata
|
|
191
381
|
payload_or_payloads.data = new_payloads.first.data
|
|
382
|
+
# External storage records the original size of a stored payload here
|
|
383
|
+
payload_or_payloads.external_payloads.replace(new_payloads.first.external_payloads.to_a)
|
|
192
384
|
when Enumerable
|
|
193
385
|
payload_or_payloads.replace(yield payload_or_payloads) # steep:ignore
|
|
194
386
|
else
|
|
@@ -241,6 +433,10 @@ module Temporalio
|
|
|
241
433
|
instance
|
|
242
434
|
end
|
|
243
435
|
|
|
436
|
+
def running_workflow_info(run_id)
|
|
437
|
+
@running_workflows_mutex.synchronize { @running_workflows[run_id] }&.info
|
|
438
|
+
end
|
|
439
|
+
|
|
244
440
|
def evict_running_workflow(run_id, cache_remove_job)
|
|
245
441
|
@running_workflows_mutex.synchronize { @running_workflows.delete(run_id) }
|
|
246
442
|
@on_eviction&.call(run_id, cache_remove_job)
|
data/lib/temporalio/version.rb
CHANGED
|
@@ -69,8 +69,9 @@ module Temporalio
|
|
|
69
69
|
# `workflow_failure_exception_type` on the workflow definition class itself. If {::Exception} is set, it
|
|
70
70
|
# effectively will fail a workflow/update in all user exception cases.
|
|
71
71
|
# @param workflow_payload_codec_thread_pool [ThreadPool, nil] Thread pool to run payload codec encode/decode
|
|
72
|
-
# within. This is
|
|
73
|
-
#
|
|
72
|
+
# within. This is also used for external storage. It is required if a payload codec or external storage exists
|
|
73
|
+
# and the worker is not fiber based. Codecs and storage drivers can potentially block execution which is why
|
|
74
|
+
# they need to be run in the background.
|
|
74
75
|
# @param unsafe_workflow_io_enabled [Boolean] If false, the default, workflow code that invokes io_wait on the
|
|
75
76
|
# fiber scheduler will fail. Instead of setting this to true, users are encouraged to use
|
|
76
77
|
# {Workflow::Unsafe.io_enabled} with a block for narrower enabling of IO.
|
|
@@ -246,7 +247,8 @@ module Temporalio
|
|
|
246
247
|
nondeterminism_as_workflow_fail_for_types:,
|
|
247
248
|
deployment_options: Worker.default_deployment_options._to_bridge_options,
|
|
248
249
|
disable_payload_error_limit: true,
|
|
249
|
-
plugins: options.plugins.map(&:name).uniq.sort
|
|
250
|
+
plugins: options.plugins.map(&:name).uniq.sort,
|
|
251
|
+
storage_drivers: (options.data_converter.external_storage&.drivers || []).map(&:type).uniq.sort
|
|
250
252
|
)
|
|
251
253
|
)
|
|
252
254
|
|
data/lib/temporalio/worker.rb
CHANGED
|
@@ -441,8 +441,9 @@ module Temporalio
|
|
|
441
441
|
# `workflow_failure_exception_type` on the workflow definition class itself. If {::Exception} is set, it
|
|
442
442
|
# effectively will fail a workflow/update in all user exception cases.
|
|
443
443
|
# @param workflow_payload_codec_thread_pool [ThreadPool, nil] Thread pool to run payload codec encode/decode within.
|
|
444
|
-
# This is
|
|
445
|
-
# execution which is why they need to
|
|
444
|
+
# This is also used for external storage. It is required if a payload codec or external storage exists and the
|
|
445
|
+
# worker is not fiber based. Codecs and storage drivers can potentially block execution which is why they need to
|
|
446
|
+
# be run in the background.
|
|
446
447
|
# @param unsafe_workflow_io_enabled [Boolean] If false, the default, workflow code that invokes io_wait on the fiber
|
|
447
448
|
# scheduler will fail. Instead of setting this to true, users are encouraged to use {Workflow::Unsafe.io_enabled}
|
|
448
449
|
# with a block for narrower enabling of IO.
|
|
@@ -608,6 +609,7 @@ module Temporalio
|
|
|
608
609
|
nondeterminism_as_workflow_fail_for_types:,
|
|
609
610
|
deployment_options: @options.deployment_options._to_bridge_options,
|
|
610
611
|
plugins: (@options.client.options.plugins + @options.plugins).map(&:name).uniq.sort,
|
|
612
|
+
storage_drivers: (@options.client.data_converter.external_storage&.drivers || []).map(&:type).uniq.sort,
|
|
611
613
|
disable_payload_error_limit: @options.disable_payload_error_limit
|
|
612
614
|
)
|
|
613
615
|
)
|