Skip to content

Commit 5d692ab

Browse files
authored
User metadata (#223)
Fixes #217
1 parent e7f19b9 commit 5d692ab

30 files changed

+510
-22
lines changed

temporalio/Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ Rake::Task[:build].enhance([:copy_parent_files]) do
9494
end
9595

9696
task :rust_lint do
97-
sh 'cargo', 'clippy', '--', '-Dwarnings'
97+
sh 'cargo', 'clippy', '-p', 'temporalio_bridge', '--no-deps', '--', '-Dwarnings'
9898
sh 'cargo', 'fmt', '--check'
9999
end
100100

temporalio/extra/proto_gen.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ def generate_import_helper_files
9595
require 'temporalio/api/errordetails/v1/message'
9696
require 'temporalio/api/export/v1/message'
9797
require 'temporalio/api/operatorservice'
98+
require 'temporalio/api/sdk/v1/workflow_metadata'
9899
require 'temporalio/api/workflowservice'
99100
100101
module Temporalio

temporalio/lib/temporalio/api.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
require 'temporalio/api/errordetails/v1/message'
66
require 'temporalio/api/export/v1/message'
77
require 'temporalio/api/operatorservice'
8+
require 'temporalio/api/sdk/v1/workflow_metadata'
89
require 'temporalio/api/workflowservice'
910

1011
module Temporalio

temporalio/lib/temporalio/client.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,12 @@ def operator_service
194194
# @param args [Array<Object>] Arguments to the workflow.
195195
# @param id [String] Unique identifier for the workflow execution.
196196
# @param task_queue [String] Task queue to run the workflow on.
197+
# @param static_summary [String, nil] Fixed single-line summary for this workflow execution that may appear in
198+
# CLI/UI. This can be in single-line Temporal markdown format. This is currently experimental.
199+
# @param static_details [String, nil] Fixed details for this workflow execution that may appear in CLI/UI. This can
200+
# be in Temporal markdown format and can be multiple lines. This is a fixed value on the workflow that cannot be
201+
# updated. For details that can be updated, use {Workflow.current_details=} within the workflow. This is currently
202+
# experimental.
197203
# @param execution_timeout [Float, nil] Total workflow execution timeout in seconds including retries and continue
198204
# as new.
199205
# @param run_timeout [Float, nil] Timeout of a single workflow run in seconds.
@@ -220,6 +226,8 @@ def start_workflow(
220226
*args,
221227
id:,
222228
task_queue:,
229+
static_summary: nil,
230+
static_details: nil,
223231
execution_timeout: nil,
224232
run_timeout: nil,
225233
task_timeout: nil,
@@ -238,6 +246,8 @@ def start_workflow(
238246
args:,
239247
workflow_id: id,
240248
task_queue:,
249+
static_summary:,
250+
static_details:,
241251
execution_timeout:,
242252
run_timeout:,
243253
task_timeout:,
@@ -260,6 +270,12 @@ def start_workflow(
260270
# @param args [Array<Object>] Arguments to the workflow.
261271
# @param id [String] Unique identifier for the workflow execution.
262272
# @param task_queue [String] Task queue to run the workflow on.
273+
# @param static_summary [String, nil] Fixed single-line summary for this workflow execution that may appear in
274+
# CLI/UI. This can be in single-line Temporal markdown format. This is currently experimental.
275+
# @param static_details [String, nil] Fixed details for this workflow execution that may appear in CLI/UI. This can
276+
# be in Temporal markdown format and can be multiple lines. This is a fixed value on the workflow that cannot be
277+
# updated. For details that can be updated, use {Workflow.current_details=} within the workflow. This is currently
278+
# experimental.
263279
# @param execution_timeout [Float, nil] Total workflow execution timeout in seconds including retries and continue
264280
# as new.
265281
# @param run_timeout [Float, nil] Timeout of a single workflow run in seconds.
@@ -287,6 +303,8 @@ def execute_workflow(
287303
*args,
288304
id:,
289305
task_queue:,
306+
static_summary: nil,
307+
static_details: nil,
290308
execution_timeout: nil,
291309
run_timeout: nil,
292310
task_timeout: nil,
@@ -305,6 +323,8 @@ def execute_workflow(
305323
*args,
306324
id:,
307325
task_queue:,
326+
static_summary:,
327+
static_details:,
308328
execution_timeout:,
309329
run_timeout:,
310330
task_timeout:,

temporalio/lib/temporalio/client/interceptor.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ def intercept_client(next_interceptor)
2323
:args,
2424
:workflow_id,
2525
:task_queue,
26+
:static_summary,
27+
:static_details,
2628
:execution_timeout,
2729
:run_timeout,
2830
:task_timeout,

temporalio/lib/temporalio/client/schedule.rb

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ def _to_proto(data_converter)
167167
:args,
168168
:id,
169169
:task_queue,
170+
:static_summary,
171+
:static_details,
170172
:execution_timeout,
171173
:run_timeout,
172174
:task_timeout,
@@ -186,6 +188,14 @@ def _to_proto(data_converter)
186188
# @return [String] Unique identifier for the workflow execution.
187189
# @!attribute task_queue
188190
# @return [String] Task queue to run the workflow on.
191+
# @!attribute static_summary
192+
# @return [String, nil] Fixed single-line summary for this workflow execution that may appear in CLI/UI.
193+
# This can be in single-line Temporal markdown format. This is currently experimental.
194+
# @!attribute static_details
195+
# @return [String, nil] Fixed details for this workflow execution that may appear in CLI/UI. This can be in
196+
# Temporal markdown format and can be multiple lines. This is a fixed value on the workflow that cannot be
197+
# updated. For details that can be updated, use {Workflow.current_details=} within the workflow. This is
198+
# currently experimental.
189199
# @!attribute execution_timeout
190200
# @return [Float, nil] Total workflow execution timeout in seconds including retries and continue as new.
191201
# @!attribute run_timeout
@@ -212,6 +222,12 @@ class << self
212222
# @param args [Array<Object>] Arguments to the workflow.
213223
# @param id [String] Unique identifier for the workflow execution.
214224
# @param task_queue [String] Task queue to run the workflow on.
225+
# @param static_summary [String, nil] Fixed single-line summary for this workflow execution that may appear
226+
# in CLI/UI. This can be in single-line Temporal markdown format. This is currently experimental.
227+
# @param static_details [String, nil] Fixed details for this workflow execution that may appear in CLI/UI.
228+
# This can be in Temporal markdown format and can be multiple lines. This is a fixed value on the workflow
229+
# that cannot be updated. For details that can be updated, use {Workflow.current_details=} within the
230+
# workflow. This is currently experimental.
215231
# @param execution_timeout [Float, nil] Total workflow execution timeout in seconds including retries and
216232
# continue as new.
217233
# @param run_timeout [Float, nil] Timeout of a single workflow run in seconds.
@@ -225,6 +241,8 @@ def new(
225241
*args,
226242
id:,
227243
task_queue:,
244+
static_summary: nil,
245+
static_details: nil,
228246
execution_timeout: nil,
229247
run_timeout: nil,
230248
task_timeout: nil,
@@ -238,6 +256,8 @@ def new(
238256
args:,
239257
id:,
240258
task_queue:,
259+
static_summary:,
260+
static_details:,
241261
execution_timeout:,
242262
run_timeout:,
243263
task_timeout:,
@@ -251,11 +271,14 @@ def new(
251271

252272
# @!visibility private
253273
def self._from_proto(raw_info, data_converter)
274+
(summary, details) = Internal::ProtoUtils.from_user_metadata(raw_info.user_metadata, data_converter)
254275
StartWorkflow.new(
255276
raw_info.workflow_type.name,
256277
*data_converter.from_payloads(raw_info.input),
257278
id: raw_info.workflow_id,
258279
task_queue: raw_info.task_queue.name,
280+
static_summary: summary,
281+
static_details: details,
259282
execution_timeout: Internal::ProtoUtils.duration_to_seconds(raw_info.workflow_execution_timeout),
260283
run_timeout: Internal::ProtoUtils.duration_to_seconds(raw_info.workflow_run_timeout),
261284
task_timeout: Internal::ProtoUtils.duration_to_seconds(raw_info.workflow_task_timeout),
@@ -280,7 +303,8 @@ def _to_proto(data_converter)
280303
retry_policy: retry_policy&._to_proto,
281304
memo: Internal::ProtoUtils.memo_to_proto(memo, data_converter),
282305
search_attributes: search_attributes&._to_proto,
283-
header: Internal::ProtoUtils.headers_to_proto(headers, data_converter)
306+
header: Internal::ProtoUtils.headers_to_proto(headers, data_converter),
307+
user_metadata: Internal::ProtoUtils.to_user_metadata(static_summary, static_details, data_converter)
284308
)
285309
)
286310
end

temporalio/lib/temporalio/client/with_start_workflow_operation.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ class WithStartWorkflowOperation
1212
:args,
1313
:id,
1414
:task_queue,
15+
:static_summary,
16+
:static_details,
1517
:execution_timeout,
1618
:run_timeout,
1719
:task_timeout,
@@ -41,6 +43,8 @@ def initialize(
4143
*args,
4244
id:,
4345
task_queue:,
46+
static_summary: nil,
47+
static_details: nil,
4448
execution_timeout: nil,
4549
run_timeout: nil,
4650
task_timeout: nil,
@@ -58,6 +62,8 @@ def initialize(
5862
args:,
5963
id:,
6064
task_queue:,
65+
static_summary:,
66+
static_details:,
6167
execution_timeout:,
6268
run_timeout:,
6369
task_timeout:,

temporalio/lib/temporalio/client/workflow_execution.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,25 @@ class Description < WorkflowExecution
9393
def initialize(raw_description, data_converter)
9494
super(raw_description.workflow_execution_info, data_converter)
9595
@raw_description = raw_description
96+
@data_converter = data_converter
97+
end
98+
99+
# @return [String, nil] Static summary configured on the workflow. This is currently experimental.
100+
def static_summary
101+
user_metadata.first
102+
end
103+
104+
# @return [String, nil] Static details configured on the workflow. This is currently experimental.
105+
def static_details
106+
user_metadata.last
107+
end
108+
109+
private
110+
111+
def user_metadata
112+
@user_metadata ||= Internal::ProtoUtils.from_user_metadata(
113+
@raw_description.execution_config&.user_metadata, @data_converter
114+
)
96115
end
97116
end
98117
end

temporalio/lib/temporalio/internal/client/implementation.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ def start_workflow(input)
6969
search_attributes: input.search_attributes&._to_proto,
7070
workflow_start_delay: ProtoUtils.seconds_to_duration(input.start_delay),
7171
request_eager_execution: input.request_eager_start,
72+
user_metadata: ProtoUtils.to_user_metadata(
73+
input.static_summary, input.static_details, @client.data_converter
74+
),
7275
header: ProtoUtils.headers_to_proto(input.headers, @client.data_converter)
7376
)
7477

@@ -319,6 +322,9 @@ def _start_workflow_request_from_with_start_options(klass, start_options)
319322
memo: ProtoUtils.memo_to_proto(start_options.memo, @client.data_converter),
320323
search_attributes: start_options.search_attributes&._to_proto,
321324
workflow_start_delay: ProtoUtils.seconds_to_duration(start_options.start_delay),
325+
user_metadata: ProtoUtils.to_user_metadata(
326+
start_options.static_summary, start_options.static_details, @client.data_converter
327+
),
322328
header: ProtoUtils.headers_to_proto(start_options.headers, @client.data_converter)
323329
)
324330
end

temporalio/lib/temporalio/internal/proto_utils.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,22 @@ def self.reserved_name?(name)
122122
name.start_with?('__temporal_') || name == '__stack_trace' || name == '__enhanced_stack_trace'
123123
end
124124

125+
def self.to_user_metadata(summary, details, converter)
126+
return nil if (!summary || summary.empty?) && (!details || details.empty?)
127+
128+
metadata = Temporalio::Api::Sdk::V1::UserMetadata.new
129+
metadata.summary = converter.to_payload(summary) if summary && !summary.empty?
130+
metadata.details = converter.to_payload(details) if details && !details.empty?
131+
metadata
132+
end
133+
134+
def self.from_user_metadata(metadata, converter)
135+
[
136+
(converter.from_payload(metadata.summary) if metadata&.summary), #: String?
137+
(converter.from_payload(metadata.details) if metadata&.details) #: String?
138+
]
139+
end
140+
125141
class LazyMemo
126142
def initialize(raw_memo, converter)
127143
@raw_memo = raw_memo

0 commit comments

Comments
 (0)