|
1 | 1 | use std::{collections::HashMap, time::Duration}; |
2 | 2 |
|
3 | 3 | use temporalio_client::Priority; |
4 | | -use temporalio_common::protos::{ |
5 | | - coresdk::{ |
6 | | - AsJsonPayloadExt, |
7 | | - child_workflow::ChildWorkflowCancellationType, |
8 | | - common::VersioningIntent, |
9 | | - nexus::NexusOperationCancellationType, |
10 | | - workflow_commands::{ |
11 | | - ActivityCancellationType, ContinueAsNewWorkflowExecution, ScheduleActivity, |
12 | | - ScheduleLocalActivity, ScheduleNexusOperation, StartChildWorkflowExecution, |
13 | | - WorkflowCommand, |
14 | | - }, |
| 4 | +use temporalio_common::{ |
| 5 | + data_converters::{ |
| 6 | + GenericPayloadConverter, PayloadConverter, SerializationContext, SerializationContextData, |
15 | 7 | }, |
16 | | - temporal::api::{ |
17 | | - common::v1::{Payload, RetryPolicy, SearchAttributes}, |
18 | | - enums::v1::{ParentClosePolicy, WorkflowIdReusePolicy}, |
19 | | - sdk::v1::UserMetadata, |
| 8 | + protos::{ |
| 9 | + coresdk::{ |
| 10 | + child_workflow::ChildWorkflowCancellationType, |
| 11 | + common::VersioningIntent, |
| 12 | + nexus::NexusOperationCancellationType, |
| 13 | + workflow_commands::{ |
| 14 | + ActivityCancellationType, ContinueAsNewWorkflowExecution, ScheduleActivity, |
| 15 | + ScheduleLocalActivity, ScheduleNexusOperation, StartChildWorkflowExecution, |
| 16 | + WorkflowCommand, |
| 17 | + }, |
| 18 | + }, |
| 19 | + temporal::api::{ |
| 20 | + common::v1::{Payload, RetryPolicy, SearchAttributes}, |
| 21 | + enums::v1::{ParentClosePolicy, WorkflowIdReusePolicy}, |
| 22 | + sdk::v1::UserMetadata, |
| 23 | + }, |
20 | 24 | }, |
21 | 25 | }; |
22 | 26 | // TODO: Before release, probably best to avoid using proto types entirely here. They're awkward. |
@@ -81,6 +85,11 @@ impl ActivityOptions { |
81 | 85 | arguments: Vec<Payload>, |
82 | 86 | seq: u32, |
83 | 87 | ) -> WorkflowCommand { |
| 88 | + let payload_converter = PayloadConverter::default(); |
| 89 | + let context = SerializationContext { |
| 90 | + data: &SerializationContextData::Workflow, |
| 91 | + converter: &payload_converter, |
| 92 | + }; |
84 | 93 | WorkflowCommand { |
85 | 94 | variant: Some( |
86 | 95 | ScheduleActivity { |
@@ -113,7 +122,8 @@ impl ActivityOptions { |
113 | 122 | user_metadata: self |
114 | 123 | .summary |
115 | 124 | .map(|s| { |
116 | | - s.as_json_payload() |
| 125 | + payload_converter |
| 126 | + .to_payload(&context, &s) |
117 | 127 | .expect("String-to-JSON payload serialization is infallible") |
118 | 128 | }) |
119 | 129 | .map(|summary| UserMetadata { |
@@ -171,6 +181,11 @@ impl LocalActivityOptions { |
171 | 181 | arguments: Vec<Payload>, |
172 | 182 | seq: u32, |
173 | 183 | ) -> WorkflowCommand { |
| 184 | + let payload_converter = PayloadConverter::default(); |
| 185 | + let context = SerializationContext { |
| 186 | + data: &SerializationContextData::Workflow, |
| 187 | + converter: &payload_converter, |
| 188 | + }; |
174 | 189 | // Allow tests to avoid extra verbosity when they don't care about timeouts |
175 | 190 | // TODO: Builderize LA options |
176 | 191 | self.schedule_to_close_timeout |
@@ -209,8 +224,8 @@ impl LocalActivityOptions { |
209 | 224 | user_metadata: self |
210 | 225 | .summary |
211 | 226 | .map(|summary| { |
212 | | - summary |
213 | | - .as_json_payload() |
| 227 | + payload_converter |
| 228 | + .to_payload(&context, &summary) |
214 | 229 | .expect("String-to-JSON payload serialization is infallible") |
215 | 230 | }) |
216 | 231 | .map(|summary| UserMetadata { |
@@ -261,14 +276,21 @@ impl ChildWorkflowOptions { |
261 | 276 | input: Vec<Payload>, |
262 | 277 | seq: u32, |
263 | 278 | ) -> WorkflowCommand { |
| 279 | + let payload_converter = PayloadConverter::default(); |
| 280 | + let context = SerializationContext { |
| 281 | + data: &SerializationContextData::Workflow, |
| 282 | + converter: &payload_converter, |
| 283 | + }; |
264 | 284 | let user_metadata = if self.static_summary.is_some() || self.static_details.is_some() { |
265 | 285 | Some(UserMetadata { |
266 | 286 | summary: self.static_summary.map(|s| { |
267 | | - s.as_json_payload() |
| 287 | + payload_converter |
| 288 | + .to_payload(&context, &s) |
268 | 289 | .expect("String-to-JSON payload serialization is infallible") |
269 | 290 | }), |
270 | 291 | details: self.static_details.map(|s| { |
271 | | - s.as_json_payload() |
| 292 | + payload_converter |
| 293 | + .to_payload(&context, &s) |
272 | 294 | .expect("String-to-JSON payload serialization is infallible") |
273 | 295 | }), |
274 | 296 | }) |
|
0 commit comments