Skip to content

Commit c78bfb6

Browse files
Support static_summary, static_details and current_details` in the Rust sdk (#1208)
* Integration test for startic summary and details. * Pin serde_json version in workspace. * Docstrings for LegacyQueryResult. * TODO to remove inline `WorkflowMetadataJson` struct once we support both normal and proto JSON serialization. * Accessors through WorkflowExecutionDescription. * TOOD: Use DataConverter to avoid direct dependency on serde_json
1 parent 08adc4a commit c78bfb6

18 files changed

Lines changed: 377 additions & 30 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ prost = "0.14"
3232
prost-types = { version = "0.7", package = "prost-wkt-types" }
3333
pbjson = "0.9"
3434
pbjson-build = "0.9"
35+
serde_json = "1.0"
3536

3637
[workspace.lints.rust]
3738
unreachable_pub = "warn"

crates/client/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ tracing = "0.1"
4242
url = "2.5"
4343
uuid = { version = "1.18", features = ["v4"] }
4444
rand = "0.10"
45+
serde_json = { workspace = true }
4546

4647
[dependencies.temporalio-common]
4748
path = "../common"

crates/client/src/lib.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ use temporalio_common::{
7272
HasWorkflowDefinition,
7373
data_converters::{DataConverter, SerializationContextData},
7474
protos::{
75-
coresdk::IntoPayloadsExt,
75+
coresdk::{AsJsonPayloadExt, IntoPayloadsExt},
7676
grpc::health::v1::health_client::HealthClient,
7777
proto_ts_to_system_time,
7878
temporal::api::{
@@ -81,6 +81,7 @@ use temporalio_common::{
8181
enums::v1::{TaskQueueKind, WorkflowExecutionStatus},
8282
errordetails::v1::WorkflowExecutionAlreadyStartedFailure,
8383
operatorservice::v1::operator_service_client::OperatorServiceClient,
84+
sdk::v1::UserMetadata,
8485
taskqueue::v1::TaskQueue,
8586
testservice::v1::test_service_client::TestServiceClient,
8687
workflow::v1 as workflow,
@@ -1030,6 +1031,22 @@ where
10301031
let workflow_id = options.workflow_id.clone();
10311032
let task_queue_name = options.task_queue.clone();
10321033

1034+
let user_metadata = if options.static_summary.is_some() || options.static_details.is_some()
1035+
{
1036+
Some(UserMetadata {
1037+
summary: options.static_summary.map(|s| {
1038+
s.as_json_payload()
1039+
.expect("String-to-JSON payload serialization is infallible")
1040+
}),
1041+
details: options.static_details.map(|s| {
1042+
s.as_json_payload()
1043+
.expect("String-to-JSON payload serialization is infallible")
1044+
}),
1045+
})
1046+
} else {
1047+
None
1048+
};
1049+
10331050
let run_id = if let Some(start_signal) = options.start_signal {
10341051
// Use signal-with-start when a start_signal is provided
10351052
let res = WorkflowService::signal_with_start_workflow_execution(
@@ -1060,6 +1077,7 @@ where
10601077
search_attributes: options.search_attributes.map(|d| d.into()),
10611078
cron_schedule: options.cron_schedule.unwrap_or_default(),
10621079
header: options.header.or(start_signal.header),
1080+
user_metadata,
10631081
..Default::default()
10641082
}
10651083
.into_request(),
@@ -1100,6 +1118,7 @@ where
11001118
completion_callbacks: options.completion_callbacks,
11011119
priority: Some(options.priority.into()),
11021120
header: options.header,
1121+
user_metadata,
11031122
..Default::default()
11041123
}
11051124
.into_request(),

crates/client/src/options_structs.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,12 @@ pub struct WorkflowStartOptions {
238238

239239
/// Headers to include with the start request.
240240
pub header: Option<Header>,
241+
242+
/// Single-line static summary for the workflow, shown in the Temporal UI.
243+
pub static_summary: Option<String>,
244+
245+
/// Multi-line static details for the workflow, shown in the Temporal UI.
246+
pub static_details: Option<String>,
241247
}
242248

243249
/// A signal to send atomically when starting a workflow.

crates/client/src/workflow_handle.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,34 @@ impl WorkflowExecutionDescription {
7373
fn new(raw_description: DescribeWorkflowExecutionResponse) -> Self {
7474
Self { raw_description }
7575
}
76+
77+
/// The static summary set when the workflow was started, if any.
78+
// TOOD: Use DataConverter to avoid direct dependency on serde_json
79+
pub fn static_summary(&self) -> Option<String> {
80+
let payload = self
81+
.raw_description
82+
.execution_config
83+
.as_ref()?
84+
.user_metadata
85+
.as_ref()?
86+
.summary
87+
.as_ref()?;
88+
serde_json::from_slice(&payload.data).ok()
89+
}
90+
91+
/// The static details set when the workflow was started, if any.
92+
// TOOD: Use DataConverter to avoid direct dependency on serde_json
93+
pub fn static_details(&self) -> Option<String> {
94+
let payload = self
95+
.raw_description
96+
.execution_config
97+
.as_ref()?
98+
.user_metadata
99+
.as_ref()?
100+
.details
101+
.as_ref()?;
102+
serde_json::from_slice(&payload.data).ok()
103+
}
76104
}
77105

78106
// TODO [rust-sdk-branch]: Could implment stream a-la ListWorkflowsStream

crates/common/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ prost-types = { workspace = true }
7575
rand = { version = "0.10", optional = true }
7676
ringbuf = { version = "0.4", optional = true }
7777
serde = { version = "1.0", features = ["derive"] }
78-
serde_json = "1.0"
78+
serde_json = { workspace = true }
7979
thiserror = { workspace = true }
8080
tokio = { version = "1.47", features = [], optional = true }
8181
toml = { version = "1.0", optional = true }

crates/common/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
158158
},
159159
&[
160160
"./protos/local/temporal/sdk/core/core_interface.proto",
161+
"./protos/api_upstream/temporal/api/sdk/v1/workflow_metadata.proto",
161162
"./protos/api_upstream/temporal/api/workflowservice/v1/service.proto",
162163
"./protos/api_upstream/temporal/api/operatorservice/v1/service.proto",
163164
"./protos/api_upstream/temporal/api/errordetails/v1/message.proto",

crates/sdk-core-c-bridge/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ prost = { workspace = true }
2929
rand = "0.10"
3030
rand_pcg = "0.10"
3131
serde = { version = "1.0", features = ["derive"] }
32-
serde_json = "1.0"
32+
serde_json = { workspace = true }
3333
tokio = "1.47"
3434
tokio-stream = "0.1"
3535
tokio-util = "0.7"

crates/sdk-core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ reqwest = { version = "0.13", features = [
7878
"rustls",
7979
], default-features = false, optional = true }
8080
serde = "1.0"
81-
serde_json = "1.0"
81+
serde_json = { workspace = true }
8282
siphasher = "1.0"
8383
slotmap = "1.0"
8484
sysinfo = { version = "0.38", default-features = false, features = ["system"] }

crates/sdk-core/src/test_help/integ_helpers.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44

55
pub use crate::{
66
internal_flags::CoreInternalFlags,
7-
worker::{LEGACY_QUERY_ID, client::mocks::mock_worker_client},
7+
worker::{
8+
LEGACY_QUERY_ID,
9+
client::{LegacyQueryResult, mocks::mock_worker_client},
10+
},
811
};
912

1013
use crate::{
@@ -16,7 +19,7 @@ use crate::{
1619
sticky_q_name_for_worker,
1720
worker::{
1821
TaskPollers, WorkerTelemetry,
19-
client::{LegacyQueryResult, MockWorkerClient, WorkerClient, WorkflowTaskCompletion},
22+
client::{MockWorkerClient, WorkerClient, WorkflowTaskCompletion},
2023
worker_config_builder,
2124
},
2225
};

0 commit comments

Comments
 (0)