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.
Files changed (138) hide show
  1. checksums.yaml +4 -4
  2. data/Cargo.lock +33 -11
  3. data/Cargo.toml +1 -0
  4. data/README.md +168 -11
  5. data/ext/Cargo.toml +3 -3
  6. data/lib/temporalio/api/cloud/account/v1/message.rb +2 -1
  7. data/lib/temporalio/api/cloud/cloudservice/v1/request_response.rb +43 -1
  8. data/lib/temporalio/api/cloud/cloudservice/v1/service.rb +1 -1
  9. data/lib/temporalio/api/cloud/connectivityrule/v1/message.rb +1 -1
  10. data/lib/temporalio/api/cloud/identity/v1/message.rb +8 -1
  11. data/lib/temporalio/api/cloud/namespace/v1/message.rb +8 -1
  12. data/lib/temporalio/api/cloud/nexus/v1/message.rb +1 -1
  13. data/lib/temporalio/api/cloud/project/v1/message.rb +28 -0
  14. data/lib/temporalio/api/cloud/region/v1/message.rb +1 -1
  15. data/lib/temporalio/api/cloud/sink/v1/message.rb +2 -1
  16. data/lib/temporalio/api/enums/v1/failed_cause.rb +1 -1
  17. data/lib/temporalio/api/enums/v1/namespace.rb +2 -1
  18. data/lib/temporalio/api/operatorservice/v1/request_response.rb +9 -1
  19. data/lib/temporalio/api/operatorservice/v1/service.rb +1 -1
  20. data/lib/temporalio/api/payload_visitor.rb +66 -0
  21. data/lib/temporalio/api/taskqueue/v1/message.rb +3 -1
  22. data/lib/temporalio/api/workflowservice/v1/request_response.rb +2 -1
  23. data/lib/temporalio/api/workflowservice/v1/service.rb +1 -1
  24. data/lib/temporalio/client/connection/cloud_service.rb +285 -0
  25. data/lib/temporalio/client/connection/operator_service.rb +45 -0
  26. data/lib/temporalio/client/schedule.rb +56 -8
  27. data/lib/temporalio/contrib/aws/s3_driver/aws_sdk_s3_storage_driver_client.rb +0 -2
  28. data/lib/temporalio/contrib/aws/s3_driver/s3_storage_driver.rb +3 -5
  29. data/lib/temporalio/contrib/aws/s3_driver/s3_storage_driver_client.rb +0 -2
  30. data/lib/temporalio/contrib/aws/s3_driver.rb +0 -2
  31. data/lib/temporalio/converters/data_converter.rb +52 -1
  32. data/lib/temporalio/converters/external_storage.rb +6 -12
  33. data/lib/temporalio/converters/external_storage_concurrency.rb +4 -2
  34. data/lib/temporalio/converters/storage_driver.rb +3 -4
  35. data/lib/temporalio/converters/storage_driver_activity_info.rb +0 -2
  36. data/lib/temporalio/converters/storage_driver_claim.rb +0 -2
  37. data/lib/temporalio/converters/storage_driver_limiter.rb +16 -0
  38. data/lib/temporalio/converters/storage_driver_retrieve_context.rb +7 -6
  39. data/lib/temporalio/converters/storage_driver_select_context.rb +11 -5
  40. data/lib/temporalio/converters/storage_driver_store_context.rb +11 -7
  41. data/lib/temporalio/converters/storage_driver_workflow_info.rb +0 -2
  42. data/lib/temporalio/error.rb +10 -3
  43. data/lib/temporalio/internal/bridge/worker.rb +1 -0
  44. data/lib/temporalio/internal/client/described_schedule_action.rb +41 -0
  45. data/lib/temporalio/internal/client/implementation.rb +92 -48
  46. data/lib/temporalio/internal/external_storage_references.rb +5 -4
  47. data/lib/temporalio/internal/external_storage_runner.rb +177 -0
  48. data/lib/temporalio/internal/storage_operation_metrics.rb +76 -0
  49. data/lib/temporalio/internal/worker/activity_worker.rb +60 -24
  50. data/lib/temporalio/internal/worker/workflow_worker.rb +211 -15
  51. data/lib/temporalio/version.rb +1 -1
  52. data/lib/temporalio/worker/workflow_replayer.rb +5 -3
  53. data/lib/temporalio/worker.rb +4 -2
  54. data/rbi/temporalio/api/cloud/account/v1/message.rbi +84 -2
  55. data/rbi/temporalio/api/cloud/cloudservice/v1/request_response.rbi +5006 -1157
  56. data/rbi/temporalio/api/cloud/cloudservice/v1/service_services.rbi +171 -0
  57. data/rbi/temporalio/api/cloud/connectivityrule/v1/message.rbi +71 -16
  58. data/rbi/temporalio/api/cloud/identity/v1/message.rbi +789 -23
  59. data/rbi/temporalio/api/cloud/namespace/v1/message.rbi +765 -15
  60. data/rbi/temporalio/api/cloud/nexus/v1/message.rbi +19 -2
  61. data/rbi/temporalio/api/cloud/project/v1/message.rbi +334 -0
  62. data/rbi/temporalio/api/cloud/region/v1/message.rbi +1 -0
  63. data/rbi/temporalio/api/cloud/sink/v1/message.rbi +147 -0
  64. data/rbi/temporalio/api/common/v1/message.rbi +6 -0
  65. data/rbi/temporalio/api/enums/v1/failed_cause.rbi +2 -0
  66. data/rbi/temporalio/api/enums/v1/namespace.rbi +20 -0
  67. data/rbi/temporalio/api/history/v1/message.rbi +40 -18
  68. data/rbi/temporalio/api/operatorservice/v1/request_response.rbi +480 -0
  69. data/rbi/temporalio/api/operatorservice/v1/service_services.rbi +32 -0
  70. data/rbi/temporalio/api/payload_visitor.rbi +33 -0
  71. data/rbi/temporalio/api/schedule/v1/message.rbi +12 -6
  72. data/rbi/temporalio/api/taskqueue/v1/message.rbi +179 -13
  73. data/rbi/temporalio/api/worker/v1/message.rbi +6 -6
  74. data/rbi/temporalio/api/workflow/v1/message.rbi +12 -6
  75. data/rbi/temporalio/api/workflowservice/v1/request_response.rbi +140 -41
  76. data/rbi/temporalio/api/workflowservice/v1/service_services.rbi +3 -0
  77. data/rbi/temporalio/client/connection/cloud_service.rbi +57 -0
  78. data/rbi/temporalio/client/connection/operator_service.rbi +9 -0
  79. data/rbi/temporalio/converters/data_converter.rbi +43 -2
  80. data/rbi/temporalio/converters/external_storage.rbi +2 -7
  81. data/rbi/temporalio/converters/storage_driver_limiter.rbi +4 -0
  82. data/rbi/temporalio/converters/storage_driver_retrieve_context.rbi +1 -1
  83. data/rbi/temporalio/converters/storage_driver_select_context.rbi +6 -2
  84. data/rbi/temporalio/converters/storage_driver_store_context.rbi +6 -2
  85. data/rbi/temporalio/error.rbi +3 -1
  86. data/rbi/temporalio/internal/bridge/api/workflow_activation/workflow_activation.rbi +6 -0
  87. data/rbi/temporalio/internal/bridge/worker.rbi +4 -2
  88. data/rbi/temporalio/internal/client/described_schedule_action.rbi +22 -0
  89. data/rbi/temporalio/internal/client/implementation.rbi +30 -0
  90. data/rbi/temporalio/internal/external_storage_runner.rbi +36 -0
  91. data/rbi/temporalio/internal/storage_operation_metrics.rbi +27 -0
  92. data/rbi/temporalio/internal/worker/activity_worker.rbi +24 -4
  93. data/rbi/temporalio/internal/worker/workflow_worker.rbi +61 -1
  94. data/rbi/temporalio/workflow.rbi +0 -12
  95. data/sig/temporalio/api/cloud/account/v1/message.rbs +30 -0
  96. data/sig/temporalio/api/cloud/cloudservice/v1/request_response.rbs +2122 -601
  97. data/sig/temporalio/api/cloud/connectivityrule/v1/message.rbs +29 -4
  98. data/sig/temporalio/api/cloud/identity/v1/message.rbs +342 -1
  99. data/sig/temporalio/api/cloud/namespace/v1/message.rbs +341 -2
  100. data/sig/temporalio/api/cloud/nexus/v1/message.rbs +9 -0
  101. data/sig/temporalio/api/cloud/project/v1/message.rbs +164 -0
  102. data/sig/temporalio/api/cloud/region/v1/message.rbs +5 -3
  103. data/sig/temporalio/api/cloud/sink/v1/message.rbs +66 -0
  104. data/sig/temporalio/api/common/v1/message.rbs +6 -0
  105. data/sig/temporalio/api/enums/v1/event_type.rbs +1 -0
  106. data/sig/temporalio/api/enums/v1/failed_cause.rbs +9 -3
  107. data/sig/temporalio/api/enums/v1/namespace.rbs +30 -2
  108. data/sig/temporalio/api/enums/v1/time_skipping.rbs +1 -0
  109. data/sig/temporalio/api/history/v1/message.rbs +8 -0
  110. data/sig/temporalio/api/operatorservice/v1/request_response.rbs +188 -0
  111. data/sig/temporalio/api/payload_visitor.rbs +11 -0
  112. data/sig/temporalio/api/schedule/v1/message.rbs +2 -0
  113. data/sig/temporalio/api/taskqueue/v1/message.rbs +66 -5
  114. data/sig/temporalio/api/worker/v1/message.rbs +2 -2
  115. data/sig/temporalio/api/workflow/v1/message.rbs +2 -0
  116. data/sig/temporalio/api/workflowservice/v1/request_response.rbs +53 -9
  117. data/sig/temporalio/client/connection/cloud_service.rbs +76 -0
  118. data/sig/temporalio/client/connection/operator_service.rbs +12 -0
  119. data/sig/temporalio/client/schedule.rbs +24 -3
  120. data/sig/temporalio/contrib/aws/s3_driver/s3_storage_driver.rbs +2 -1
  121. data/sig/temporalio/contrib/open_telemetry.rbs +4 -4
  122. data/sig/temporalio/converters/data_converter.rbs +19 -1
  123. data/sig/temporalio/converters/external_storage.rbs +1 -3
  124. data/sig/temporalio/converters/storage_driver_limiter.rbs +5 -0
  125. data/sig/temporalio/converters/storage_driver_retrieve_context.rbs +1 -1
  126. data/sig/temporalio/converters/storage_driver_select_context.rbs +3 -1
  127. data/sig/temporalio/converters/storage_driver_store_context.rbs +3 -1
  128. data/sig/temporalio/error.rbs +4 -1
  129. data/sig/temporalio/internal/bridge/api/workflow_activation/workflow_activation.rbs +4 -0
  130. data/sig/temporalio/internal/bridge/worker.rbs +2 -0
  131. data/sig/temporalio/internal/client/described_schedule_action.rbs +18 -0
  132. data/sig/temporalio/internal/client/implementation.rbs +22 -0
  133. data/sig/temporalio/internal/external_storage_runner.rbs +32 -0
  134. data/sig/temporalio/internal/storage_operation_metrics.rbs +25 -0
  135. data/sig/temporalio/internal/worker/activity_worker.rbs +11 -2
  136. data/sig/temporalio/internal/worker/workflow_worker.rbs +32 -1
  137. metadata +13 -2
  138. data/sig/open_telemetry.rbs +0 -47
@@ -2,6 +2,8 @@
2
2
 
3
3
  require 'temporalio/api'
4
4
  require 'temporalio/converters'
5
+ require 'temporalio/converters/storage_driver_workflow_info'
6
+ require 'temporalio/internal/client/described_schedule_action'
5
7
  require 'temporalio/internal/proto_utils'
6
8
  require 'temporalio/priority'
7
9
  require 'temporalio/retry_policy'
@@ -48,10 +50,10 @@ module Temporalio
48
50
  end
49
51
 
50
52
  # @!visibility private
51
- def _to_proto(data_converter)
53
+ def _to_proto(data_converter, namespace, described_action = nil)
52
54
  Api::Schedule::V1::Schedule.new(
53
55
  spec: spec._to_proto,
54
- action: action._to_proto(data_converter),
56
+ action: action._to_proto(data_converter, namespace, described_action),
55
57
  policies: policy._to_proto,
56
58
  state: state._to_proto
57
59
  )
@@ -159,10 +161,15 @@ module Temporalio
159
161
  end
160
162
 
161
163
  # @!visibility private
162
- def _to_proto(data_converter)
164
+ def _to_proto(data_converter, namespace, described = nil)
163
165
  raise NotImplementedError
164
166
  end
165
167
 
168
+ # @!visibility private
169
+ def _described(_raw_action)
170
+ nil
171
+ end
172
+
166
173
  StartWorkflow = Data.define(
167
174
  :workflow,
168
175
  :args,
@@ -305,25 +312,66 @@ module Temporalio
305
312
  end
306
313
 
307
314
  # @!visibility private
308
- def _to_proto(data_converter)
315
+ def _to_proto(data_converter, namespace, described = nil)
316
+ raw_info = described&.raw_info
317
+ workflow_type = workflow #: String
318
+ workflow_data_converter = data_converter._with_storage_target(
319
+ namespace:, target: Converters::StorageDriverWorkflowInfo.new(namespace:, id:, type: workflow_type)
320
+ )
309
321
  Api::Schedule::V1::ScheduleAction.new(
310
322
  start_workflow: Api::Workflow::V1::NewWorkflowExecutionInfo.new(
311
323
  workflow_id: id,
312
324
  workflow_type: Api::Common::V1::WorkflowType.new(name: workflow),
313
325
  task_queue: Api::TaskQueue::V1::TaskQueue.new(name: task_queue),
314
- input: data_converter.to_payloads(args, hints: arg_hints),
326
+ input: if described&.unchanged?(:args, args)
327
+ raw_info&.input
328
+ else
329
+ workflow_data_converter.to_payloads(args, hints: arg_hints)
330
+ end,
315
331
  workflow_execution_timeout: Internal::ProtoUtils.seconds_to_duration(execution_timeout),
316
332
  workflow_run_timeout: Internal::ProtoUtils.seconds_to_duration(run_timeout),
317
333
  workflow_task_timeout: Internal::ProtoUtils.seconds_to_duration(task_timeout),
318
334
  retry_policy: retry_policy&._to_proto,
319
- memo: Internal::ProtoUtils.memo_to_proto(memo, data_converter),
335
+ memo: if described&.unchanged?(:memo, memo)
336
+ raw_info&.memo
337
+ else
338
+ Internal::ProtoUtils.memo_to_proto(memo, workflow_data_converter)
339
+ end,
320
340
  search_attributes: search_attributes&._to_proto,
321
- header: Internal::ProtoUtils.headers_to_proto(headers, data_converter),
341
+ header: if described&.unchanged?(:headers, headers)
342
+ raw_info&.header
343
+ else
344
+ Internal::ProtoUtils.headers_to_proto(headers, workflow_data_converter)
345
+ end,
322
346
  priority: priority._to_proto,
323
- user_metadata: Internal::ProtoUtils.to_user_metadata(static_summary, static_details, data_converter)
347
+ user_metadata: _user_metadata_to_proto(workflow_data_converter, described)
324
348
  )
325
349
  )
326
350
  end
351
+
352
+ # @!visibility private
353
+ def _described(raw_action)
354
+ Internal::Client::DescribedScheduleAction.new(self, raw_action.start_workflow)
355
+ end
356
+
357
+ private
358
+
359
+ def _user_metadata_to_proto(data_converter, described)
360
+ summary_unchanged = described&.unchanged_text?(:static_summary, static_summary)
361
+ details_unchanged = described&.unchanged_text?(:static_details, static_details)
362
+ metadata = Internal::ProtoUtils.to_user_metadata(
363
+ (static_summary unless summary_unchanged),
364
+ (static_details unless details_unchanged),
365
+ data_converter
366
+ )
367
+ return metadata unless summary_unchanged || details_unchanged
368
+
369
+ raw_metadata = described&.raw_info&.user_metadata
370
+ metadata ||= Api::Sdk::V1::UserMetadata.new
371
+ metadata.summary = raw_metadata&.summary if summary_unchanged
372
+ metadata.details = raw_metadata&.details if details_unchanged
373
+ metadata
374
+ end
327
375
  end
328
376
  end
329
377
 
@@ -10,8 +10,6 @@ module Temporalio
10
10
  # {S3StorageDriverClient} backed by an +Aws::S3::Client+ from the official +aws-sdk-s3+ gem.
11
11
  #
12
12
  # @note WARNING: This API is experimental and may change in the future.
13
- #
14
- # @!visibility private
15
13
  class AwsSdkS3StorageDriverClient < S3StorageDriverClient
16
14
  # Create a client.
17
15
  #
@@ -20,8 +20,6 @@ module Temporalio
20
20
  # the payload is stored for, percent-encoded to S3's safe character set.
21
21
  #
22
22
  # @note WARNING: This API is experimental and may change in the future.
23
- #
24
- # @!visibility private
25
23
  class S3StorageDriver < Converters::StorageDriver
26
24
  # Driver type shared by every S3 driver instance across SDK languages.
27
25
  DRIVER_TYPE = 'aws.s3driver'
@@ -71,7 +69,7 @@ module Temporalio
71
69
 
72
70
  # (see Converters::StorageDriver#store)
73
71
  def store(context, payloads)
74
- context_segments = context_key_segments(context.target)
72
+ context_segments = context_key_segments(context.target, context.namespace)
75
73
  objects = payloads.map { |payload| stored_object(context, payload, context_segments) }
76
74
  uploads = objects.uniq { |object| [object.bucket, object.key] }
77
75
  run_concurrently(uploads, context.cancellation) do |object, cancellation|
@@ -179,7 +177,7 @@ module Temporalio
179
177
  results
180
178
  end
181
179
 
182
- def context_key_segments(target)
180
+ def context_key_segments(target, namespace)
183
181
  case target
184
182
  when Converters::StorageDriverWorkflowInfo
185
183
  "/ns/#{encode_key_segment(target.namespace)}/wt/#{encode_key_segment(target.type)}" \
@@ -188,7 +186,7 @@ module Temporalio
188
186
  "/ns/#{encode_key_segment(target.namespace)}/at/#{encode_key_segment(target.type)}" \
189
187
  "/ai/#{encode_key_segment(target.id)}/ri/#{encode_key_segment(target.run_id)}"
190
188
  else
191
- ''
189
+ "/ns/#{encode_key_segment(namespace)}"
192
190
  end
193
191
  end
194
192
 
@@ -12,8 +12,6 @@ module Temporalio
12
12
  # Implementations are called concurrently from multiple threads and must be thread safe.
13
13
  #
14
14
  # @note WARNING: This API is experimental and may change in the future.
15
- #
16
- # @!visibility private
17
15
  class S3StorageDriverClient
18
16
  # Upload data to the given bucket and key.
19
17
  #
@@ -13,8 +13,6 @@ module Temporalio
13
13
  # +temporalio/contrib/aws/s3_driver/aws_sdk_s3_storage_driver_client+ to use the official AWS client.
14
14
  #
15
15
  # @note WARNING: This API is experimental and may change in the future.
16
- #
17
- # @!visibility private
18
16
  module S3Driver
19
17
  end
20
18
  end
@@ -1,9 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'temporalio/api'
4
+ require 'temporalio/converters/external_storage'
4
5
  require 'temporalio/converters/failure_converter'
5
6
  require 'temporalio/converters/payload_codec'
6
7
  require 'temporalio/converters/payload_converter'
8
+ require 'temporalio/internal/external_storage_runner'
7
9
 
8
10
  module Temporalio
9
11
  module Converters
@@ -18,6 +20,11 @@ module Temporalio
18
20
  # @return [PayloadCodec, nil] Optional codec for encoding/decoding payload bytes such as for encryption.
19
21
  attr_reader :payload_codec
20
22
 
23
+ # @return [ExternalStorage, nil] Optional storage for offloading large payloads.
24
+ #
25
+ # @note WARNING: This API is experimental and may change in the future.
26
+ attr_reader :external_storage
27
+
21
28
  # @return [DataConverter] Default data converter.
22
29
  def self.default
23
30
  @default ||= DataConverter.new
@@ -28,14 +35,44 @@ module Temporalio
28
35
  # @param payload_converter [PayloadConverter] Payload converter to use.
29
36
  # @param failure_converter [FailureConverter] Failure converter to use.
30
37
  # @param payload_codec [PayloadCodec, nil] Payload codec to use.
38
+ # @param external_storage [ExternalStorage, nil] External storage for offloading large payloads. WARNING: External
39
+ # storage is experimental.
31
40
  def initialize(
32
41
  payload_converter: PayloadConverter.default,
33
42
  failure_converter: FailureConverter.default,
34
- payload_codec: nil
43
+ payload_codec: nil,
44
+ external_storage: nil
35
45
  )
36
46
  @payload_converter = payload_converter
37
47
  @failure_converter = failure_converter
38
48
  @payload_codec = payload_codec
49
+ @external_storage = external_storage
50
+ # Retrieving runs even without storage, so a reference is reported rather than decoded as an ordinary value.
51
+ @external_storage_runner = Internal::ExternalStorageRunner.new(external_storage, namespace: nil)
52
+ @storage_target = nil
53
+ end
54
+
55
+ # Copy of this converter whose stores tell drivers the namespace and the execution the payloads belong to.
56
+ #
57
+ # @param namespace [String, nil] Namespace of the client or worker storing through the copy.
58
+ # @param target [StorageDriverWorkflowInfo, StorageDriverActivityInfo, nil] Execution the payloads are stored on
59
+ # behalf of.
60
+ # @return [DataConverter] The copy.
61
+ #
62
+ # @!visibility private
63
+ def _with_storage_target(namespace:, target:)
64
+ return self unless external_storage
65
+
66
+ dup.tap { |converter| converter.send(:set_storage, external_storage, namespace:, target:) }
67
+ end
68
+
69
+ # Copy of this converter that never stores or retrieves payloads. Converters and codec are kept.
70
+ #
71
+ # @return [DataConverter] The copy.
72
+ #
73
+ # @!visibility private
74
+ def _without_storage
75
+ dup.tap { |converter| converter.send(:set_storage, nil, namespace: nil, target: nil) }
39
76
  end
40
77
 
41
78
  # Convert a Ruby value to a payload and encode it.
@@ -46,6 +83,7 @@ module Temporalio
46
83
  def to_payload(value, hint: nil)
47
84
  payload = payload_converter.to_payload(value, hint:)
48
85
  payload = payload_codec.encode([payload]).first if payload_codec
86
+ payload = @external_storage_runner.store([payload], target: @storage_target).first if external_storage
49
87
  payload
50
88
  end
51
89
 
@@ -60,6 +98,9 @@ module Temporalio
60
98
  def to_payloads(values, hints: nil)
61
99
  payloads = payload_converter.to_payloads(values, hints:)
62
100
  payloads.payloads.replace(payload_codec.encode(payloads.payloads)) if payload_codec && !payloads.payloads.empty?
101
+ if external_storage && !payloads.payloads.empty?
102
+ payloads.payloads.replace(@external_storage_runner.store(payloads.payloads.to_a, target: @storage_target))
103
+ end
63
104
  payloads
64
105
  end
65
106
 
@@ -69,6 +110,7 @@ module Temporalio
69
110
  # @param hint [Object, nil] Hint, if any, to assist conversion.
70
111
  # @return [Object] Decoded and converted Ruby value.
71
112
  def from_payload(payload, hint: nil)
113
+ payload = @external_storage_runner.retrieve([payload]).first
72
114
  payload = payload_codec.decode([payload]).first if payload_codec
73
115
  payload_converter.from_payload(payload, hint:)
74
116
  end
@@ -84,6 +126,7 @@ module Temporalio
84
126
  def from_payloads(payloads, hints: nil)
85
127
  return [] unless payloads && !payloads.payloads.empty?
86
128
 
129
+ payloads = Api::Common::V1::Payloads.new(payloads: @external_storage_runner.retrieve(payloads.payloads.to_a))
87
130
  if payload_codec && !payloads.payloads.empty?
88
131
  payloads = Api::Common::V1::Payloads.new(payloads: payload_codec.decode(payloads.payloads))
89
132
  end
@@ -105,6 +148,14 @@ module Temporalio
105
148
  def from_failure(failure)
106
149
  failure_converter.from_failure(failure, self)
107
150
  end
151
+
152
+ private
153
+
154
+ def set_storage(external_storage, namespace:, target:)
155
+ @external_storage = external_storage
156
+ @external_storage_runner = Internal::ExternalStorageRunner.new(external_storage, namespace:)
157
+ @storage_target = target
158
+ end
108
159
  end
109
160
  end
110
161
  end
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'temporalio/converters/external_storage_concurrency'
4
3
  require 'temporalio/converters/storage_driver'
5
4
 
6
5
  module Temporalio
@@ -11,8 +10,6 @@ module Temporalio
11
10
  # the first payload large enough to offload.
12
11
  #
13
12
  # @note WARNING: This API is experimental and may change in the future.
14
- #
15
- # @!visibility private
16
13
  class ExternalStorage
17
14
  # Shared with every other SDK, so the same payload offloads regardless of which one wrote it.
18
15
  DEFAULT_PAYLOAD_SIZE_THRESHOLD = 256 * 1024
@@ -25,9 +22,6 @@ module Temporalio
25
22
  # Only called for payloads that meet {#payload_size_threshold}, and must return one of {#drivers} or nil.
26
23
  attr_reader :driver_selector
27
24
 
28
- # @return [ExternalStorageConcurrency] Limits on how many storage requests may be in flight at once.
29
- attr_reader :concurrency
30
-
31
25
  # @return [Integer] Minimum encoded payload size, in bytes, that is offloaded. Payloads at or above this size are
32
26
  # offloaded; smaller ones are left inline. Zero offloads every payload.
33
27
  attr_reader :payload_size_threshold
@@ -35,19 +29,18 @@ module Temporalio
35
29
  # Create external storage configuration.
36
30
  #
37
31
  # @param drivers [Array<StorageDriver>] Drivers available for storing and retrieving payloads. At least one is
38
- # required, and every driver must have a unique, non-empty name. Retrieval routes by the name recorded in
39
- # history, so a driver must remain configured for as long as any payload it stored can still be read.
32
+ # required, every driver must have a unique, non-empty name, and every driver must have a String type.
33
+ # Retrieval routes by the name recorded in history, so a driver must remain configured for as long as any
34
+ # payload it stored can still be read.
40
35
  # @param driver_selector [Proc, nil] Selector choosing which driver stores each payload. Required when more than
41
36
  # one driver is given; with a single driver it may be nil, in which case that driver stores every eligible
42
37
  # payload.
43
38
  # @param payload_size_threshold [Integer] Minimum encoded payload size, in bytes, to offload. Must be a
44
39
  # non-negative Integer.
45
- # @param concurrency [ExternalStorageConcurrency] Limits on how many storage requests may be in flight at once.
46
40
  def initialize(
47
41
  drivers:,
48
42
  driver_selector: nil,
49
- payload_size_threshold: DEFAULT_PAYLOAD_SIZE_THRESHOLD,
50
- concurrency: ExternalStorageConcurrency.new
43
+ payload_size_threshold: DEFAULT_PAYLOAD_SIZE_THRESHOLD
51
44
  )
52
45
  raise ArgumentError, 'At least one driver is required' if drivers.empty?
53
46
 
@@ -67,6 +60,8 @@ module Temporalio
67
60
  raise ArgumentError, 'Driver name must be a non-empty String' unless name.is_a?(String) && !name.empty?
68
61
  raise ArgumentError, "Multiple drivers given with name '#{name}'" if @drivers_by_name.key?(name)
69
62
 
63
+ raise ArgumentError, "Driver '#{name}' type must be a String" unless driver.type.is_a?(String)
64
+
70
65
  @drivers_by_name[name] = driver
71
66
  end
72
67
  @drivers_by_name.freeze
@@ -75,7 +70,6 @@ module Temporalio
75
70
  # Normalized so callers never have to distinguish the single-driver case.
76
71
  @driver_selector = driver_selector || ->(_context, _payload) { @drivers.first }
77
72
  @payload_size_threshold = payload_size_threshold
78
- @concurrency = concurrency
79
73
  end
80
74
 
81
75
  # Get the driver registered under the given name.
@@ -7,8 +7,10 @@ module Temporalio
7
7
  :max_operations_per_message
8
8
  )
9
9
 
10
- # Limits on how many external storage requests may be in flight at once. Set on
11
- # {ExternalStorage#concurrency}.
10
+ # Limits on how many external storage requests may be in flight at once.
11
+ #
12
+ # {ExternalStorage} does not accept these limits yet, because the SDK does not enforce them. This class is kept to
13
+ # record the defaults shared with the other SDKs until enforcement is added.
12
14
  #
13
15
  # @note WARNING: This API is experimental and may change in the future.
14
16
  #
@@ -14,8 +14,6 @@ module Temporalio
14
14
  # pool instead of a fiber scheduler. {Temporalio::Worker::ThreadPool} can be used to bound that fan out.
15
15
  #
16
16
  # @note WARNING: This API is experimental and may change in the future.
17
- #
18
- # @!visibility private
19
17
  class StorageDriver
20
18
  # Name of this driver instance, unique among the drivers registered on one {ExternalStorage}. This is written
21
19
  # into history alongside every payload the driver stores and is used to route retrieval back to the same driver.
@@ -27,11 +25,12 @@ module Temporalio
27
25
  end
28
26
 
29
27
  # Identifier for this driver implementation, for example +aws.s3driver+. Unlike {#name}, this is identical across
30
- # every instance of the same implementation and across SDK languages.
28
+ # every instance of the same implementation and across SDK languages. Reported in the worker heartbeat. Must be
29
+ # implemented.
31
30
  #
32
31
  # @return [String] Driver implementation identifier.
33
32
  def type
34
- raise NotImplementedError
33
+ raise NotImplementedError, "#{self.class} must implement #type"
35
34
  end
36
35
 
37
36
  # Store the given payloads.
@@ -21,8 +21,6 @@ module Temporalio
21
21
  # @return [String, nil] Run ID, if known.
22
22
  # @!attribute [r] type
23
23
  # @return [String, nil] Activity type name, if known.
24
- #
25
- # @!visibility private
26
24
  class StorageDriverActivityInfo
27
25
  # Create activity target information.
28
26
  #
@@ -11,8 +11,6 @@ module Temporalio
11
11
  # @!attribute [r] claim_data
12
12
  # @return [Hash<String, String>] Data the driver needs to retrieve the payload. This is written into history, so
13
13
  # it must contain everything required for retrieval and must not contain secrets.
14
- #
15
- # @!visibility private
16
14
  class StorageDriverClaim
17
15
  # Create a claim.
18
16
  #
@@ -13,6 +13,22 @@ module Temporalio
13
13
  #
14
14
  # @!visibility private
15
15
  class StorageDriverLimiter
16
+ # Limiter that grants every permit immediately. {StorageDriverStoreContext} and {StorageDriverRetrieveContext}
17
+ # use it by default, because the SDK does not enforce concurrency limits yet.
18
+ #
19
+ # @!visibility private
20
+ class Unbounded < StorageDriverLimiter
21
+ # (see StorageDriverLimiter#permit)
22
+ def permit(_item)
23
+ yield
24
+ end
25
+ end
26
+
27
+ # Shared instance of {Unbounded}.
28
+ #
29
+ # @!visibility private
30
+ UNBOUNDED = Unbounded.new
31
+
16
32
  # Hold a permit for the duration of the given block, waiting for one to be available before the block runs
17
33
  # and releasing it when the block returns or raises.
18
34
  #
@@ -19,11 +19,12 @@ module Temporalio
19
19
  # arguments defensively if constructing this yourself.
20
20
  #
21
21
  # @!attribute [r] cancellation
22
- # @return [Cancellation] Cancelled when the SDK abandons this retrieve operation.
23
- # @!attribute [r] limiter
24
- # @return [StorageDriverLimiter] Limiter for this driver's retrieve requests.
25
- #
26
- # @!visibility private
27
- class StorageDriverRetrieveContext; end # rubocop:disable Lint/EmptyClass
22
+ # @return [Cancellation] Cancellation for this retrieve operation. The SDK does not cancel it yet. Drivers may
23
+ # still check it, so that they stop early once the SDK does.
24
+ class StorageDriverRetrieveContext
25
+ def initialize(cancellation:, limiter: StorageDriverLimiter::UNBOUNDED)
26
+ super
27
+ end
28
+ end
28
29
  end
29
30
  end
@@ -6,7 +6,8 @@ module Temporalio
6
6
  module Converters
7
7
  StorageDriverSelectContext = Data.define(
8
8
  :target,
9
- :cancellation
9
+ :cancellation,
10
+ :namespace
10
11
  )
11
12
 
12
13
  # Context given to the driver selector.
@@ -18,9 +19,14 @@ module Temporalio
18
19
  # @return [StorageDriverWorkflowInfo, StorageDriverActivityInfo, nil] The execution the payload is being stored
19
20
  # on behalf of, or nil when there is no associated execution.
20
21
  # @!attribute [r] cancellation
21
- # @return [Cancellation] Cancelled when the SDK abandons the operation this selection is part of.
22
- #
23
- # @!visibility private
24
- class StorageDriverSelectContext; end # rubocop:disable Lint/EmptyClass
22
+ # @return [Cancellation] Cancellation for the operation this selection is part of. The SDK does not cancel it
23
+ # yet.
24
+ # @!attribute [r] namespace
25
+ # @return [String, nil] Namespace of the client or worker performing the store, or nil when it is not known.
26
+ class StorageDriverSelectContext
27
+ def initialize(target:, cancellation:, namespace: nil)
28
+ super
29
+ end
30
+ end
25
31
  end
26
32
  end
@@ -8,7 +8,8 @@ module Temporalio
8
8
  StorageDriverStoreContext = Data.define(
9
9
  :target,
10
10
  :cancellation,
11
- :limiter
11
+ :limiter,
12
+ :namespace
12
13
  )
13
14
 
14
15
  # Context given to {StorageDriver#store}.
@@ -20,11 +21,14 @@ module Temporalio
20
21
  # @return [StorageDriverWorkflowInfo, StorageDriverActivityInfo, nil] The execution the payloads are being stored
21
22
  # on behalf of, or nil when there is no associated execution.
22
23
  # @!attribute [r] cancellation
23
- # @return [Cancellation] Cancelled when the SDK abandons this store operation.
24
- # @!attribute [r] limiter
25
- # @return [StorageDriverLimiter] Limiter for this driver's store requests.
26
- #
27
- # @!visibility private
28
- class StorageDriverStoreContext; end # rubocop:disable Lint/EmptyClass
24
+ # @return [Cancellation] Cancellation for this store operation. The SDK does not cancel it yet. Drivers may still
25
+ # check it, so that they stop early once the SDK does.
26
+ # @!attribute [r] namespace
27
+ # @return [String, nil] Namespace of the client or worker performing the store, or nil when it is not known.
28
+ class StorageDriverStoreContext
29
+ def initialize(target:, cancellation:, limiter: StorageDriverLimiter::UNBOUNDED, namespace: nil)
30
+ super
31
+ end
32
+ end
29
33
  end
30
34
  end
@@ -23,8 +23,6 @@ module Temporalio
23
23
  # workflow or continuing as new.
24
24
  # @!attribute [r] type
25
25
  # @return [String, nil] Workflow type name, if known.
26
- #
27
- # @!visibility private
28
26
  class StorageDriverWorkflowInfo
29
27
  # Create workflow target information.
30
28
  #
@@ -116,14 +116,21 @@ module Temporalio
116
116
  end
117
117
  end
118
118
 
119
+ # Error that occurs when storing payloads in, or retrieving them from, external storage fails. This is the base
120
+ # for every external storage failure.
121
+ #
122
+ # @note WARNING: This API is experimental and may change in the future.
123
+ #
124
+ # @!visibility private
125
+ class ExternalStorageError < Error
126
+ end
127
+
119
128
  # Error that occurs when a payload stored in external storage is encountered but no external storage is
120
129
  # configured to retrieve it. This usually means the client or worker reading the payload is configured
121
130
  # differently from the one that wrote it.
122
131
  #
123
132
  # @note WARNING: This API is experimental and may change in the future.
124
- #
125
- # @!visibility private
126
- class ExternalStorageNotConfiguredError < Error
133
+ class ExternalStorageNotConfiguredError < ExternalStorageError
127
134
  # @!visibility private
128
135
  def initialize(
129
136
  message = '[TMPRL1105] Encountered a reference to a payload in external storage, but no external storage ' \
@@ -30,6 +30,7 @@ module Temporalio
30
30
  :nondeterminism_as_workflow_fail_for_types,
31
31
  :deployment_options,
32
32
  :plugins,
33
+ :storage_drivers,
33
34
  :disable_payload_error_limit
34
35
  )
35
36
 
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Temporalio
4
+ module Internal
5
+ module Client
6
+ # The start-workflow action a schedule update started from. Members the updater leaves unchanged are sent back
7
+ # as the payloads they were described from, since encoding them again would store another copy on every update.
8
+ class DescribedScheduleAction
9
+ attr_reader :raw_info
10
+
11
+ def initialize(action, raw_info)
12
+ @raw_info = raw_info
13
+ # Data#with keeps the members it does not replace, and these copies catch a member changed in place.
14
+ @members = %i[args memo headers].to_h do |name|
15
+ value = action.public_send(name)
16
+ [name, [value, value.dup]]
17
+ end
18
+ @texts = %i[static_summary static_details].to_h { |name| [name, action.public_send(name).dup] }
19
+ end
20
+
21
+ def unchanged?(name, value)
22
+ described, copy = @members.fetch(name)
23
+ return false unless value.equal?(described)
24
+
25
+ case value
26
+ when Array
27
+ copy.is_a?(Array) && value.size == copy.size && value.each_with_index.all? { |v, i| v.equal?(copy[i]) }
28
+ when Hash
29
+ copy.is_a?(Hash) && value.size == copy.size && copy.all? { |k, v| value.key?(k) && value[k].equal?(v) }
30
+ else
31
+ true
32
+ end
33
+ end
34
+
35
+ def unchanged_text?(name, value)
36
+ !value.nil? && !value.empty? && value == @texts.fetch(name)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end