@temporalio/core-bridge 1.11.7 → 1.11.8

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 (191) hide show
  1. package/Cargo.lock +504 -341
  2. package/package.json +3 -3
  3. package/releases/aarch64-apple-darwin/index.node +0 -0
  4. package/releases/aarch64-unknown-linux-gnu/index.node +0 -0
  5. package/releases/x86_64-apple-darwin/index.node +0 -0
  6. package/releases/x86_64-pc-windows-msvc/index.node +0 -0
  7. package/releases/x86_64-unknown-linux-gnu/index.node +0 -0
  8. package/sdk-core/.cargo/config.toml +5 -0
  9. package/sdk-core/.github/workflows/per-pr.yml +59 -5
  10. package/sdk-core/Cargo.toml +3 -2
  11. package/sdk-core/client/Cargo.toml +3 -3
  12. package/sdk-core/client/src/lib.rs +154 -161
  13. package/sdk-core/client/src/metrics.rs +15 -8
  14. package/sdk-core/client/src/proxy.rs +1 -1
  15. package/sdk-core/client/src/raw.rs +176 -33
  16. package/sdk-core/client/src/retry.rs +102 -465
  17. package/sdk-core/client/src/worker_registry/mod.rs +2 -2
  18. package/sdk-core/client/src/workflow_handle/mod.rs +19 -1
  19. package/sdk-core/core/Cargo.toml +12 -14
  20. package/sdk-core/core/benches/workflow_replay.rs +1 -1
  21. package/sdk-core/core/src/abstractions.rs +2 -2
  22. package/sdk-core/core/src/core_tests/activity_tasks.rs +99 -46
  23. package/sdk-core/core/src/core_tests/child_workflows.rs +68 -9
  24. package/sdk-core/core/src/core_tests/determinism.rs +2 -2
  25. package/sdk-core/core/src/core_tests/local_activities.rs +20 -33
  26. package/sdk-core/core/src/core_tests/mod.rs +7 -8
  27. package/sdk-core/core/src/core_tests/queries.rs +79 -79
  28. package/sdk-core/core/src/core_tests/replay_flag.rs +5 -5
  29. package/sdk-core/core/src/core_tests/updates.rs +6 -6
  30. package/sdk-core/core/src/core_tests/workers.rs +19 -22
  31. package/sdk-core/core/src/core_tests/workflow_cancels.rs +3 -3
  32. package/sdk-core/core/src/core_tests/workflow_tasks.rs +154 -106
  33. package/sdk-core/core/src/ephemeral_server/mod.rs +66 -10
  34. package/sdk-core/core/src/internal_flags.rs +103 -12
  35. package/sdk-core/core/src/lib.rs +21 -13
  36. package/sdk-core/core/src/pollers/mod.rs +200 -6
  37. package/sdk-core/core/src/pollers/poll_buffer.rs +32 -8
  38. package/sdk-core/core/src/protosext/mod.rs +7 -7
  39. package/sdk-core/core/src/protosext/protocol_messages.rs +2 -2
  40. package/sdk-core/core/src/replay/mod.rs +8 -9
  41. package/sdk-core/core/src/retry_logic.rs +8 -6
  42. package/sdk-core/core/src/telemetry/log_export.rs +4 -4
  43. package/sdk-core/core/src/telemetry/metrics.rs +111 -25
  44. package/sdk-core/core/src/telemetry/mod.rs +11 -4
  45. package/sdk-core/core/src/telemetry/otel.rs +108 -144
  46. package/sdk-core/core/src/telemetry/prometheus_server.rs +1 -4
  47. package/sdk-core/core/src/test_help/mod.rs +27 -21
  48. package/sdk-core/core/src/worker/activities/activity_heartbeat_manager.rs +7 -5
  49. package/sdk-core/core/src/worker/activities/local_activities.rs +9 -9
  50. package/sdk-core/core/src/worker/activities.rs +34 -46
  51. package/sdk-core/core/src/worker/client/mocks.rs +24 -2
  52. package/sdk-core/core/src/worker/client.rs +169 -33
  53. package/sdk-core/core/src/worker/mod.rs +132 -56
  54. package/sdk-core/core/src/worker/nexus.rs +410 -0
  55. package/sdk-core/core/src/worker/tuner/resource_based.rs +27 -5
  56. package/sdk-core/core/src/worker/tuner.rs +29 -2
  57. package/sdk-core/core/src/worker/workflow/driven_workflow.rs +8 -3
  58. package/sdk-core/core/src/worker/workflow/history_update.rs +5 -8
  59. package/sdk-core/core/src/worker/workflow/machines/activity_state_machine.rs +83 -87
  60. package/sdk-core/core/src/worker/workflow/machines/cancel_external_state_machine.rs +38 -38
  61. package/sdk-core/core/src/worker/workflow/machines/cancel_nexus_op_state_machine.rs +117 -0
  62. package/sdk-core/core/src/worker/workflow/machines/cancel_workflow_state_machine.rs +8 -18
  63. package/sdk-core/core/src/worker/workflow/machines/child_workflow_state_machine.rs +114 -108
  64. package/sdk-core/core/src/worker/workflow/machines/complete_workflow_state_machine.rs +16 -31
  65. package/sdk-core/core/src/worker/workflow/machines/continue_as_new_workflow_state_machine.rs +7 -14
  66. package/sdk-core/core/src/worker/workflow/machines/fail_workflow_state_machine.rs +8 -15
  67. package/sdk-core/core/src/worker/workflow/machines/local_activity_state_machine.rs +34 -75
  68. package/sdk-core/core/src/worker/workflow/machines/mod.rs +26 -48
  69. package/sdk-core/core/src/worker/workflow/machines/modify_workflow_properties_state_machine.rs +10 -17
  70. package/sdk-core/core/src/worker/workflow/machines/nexus_operation_state_machine.rs +543 -0
  71. package/sdk-core/core/src/worker/workflow/machines/patch_state_machine.rs +22 -31
  72. package/sdk-core/core/src/worker/workflow/machines/signal_external_state_machine.rs +53 -51
  73. package/sdk-core/core/src/worker/workflow/machines/timer_state_machine.rs +40 -45
  74. package/sdk-core/core/src/worker/workflow/machines/transition_coverage.rs +2 -2
  75. package/sdk-core/core/src/worker/workflow/machines/update_state_machine.rs +8 -10
  76. package/sdk-core/core/src/worker/workflow/machines/upsert_search_attributes_state_machine.rs +24 -30
  77. package/sdk-core/core/src/worker/workflow/machines/workflow_machines.rs +182 -116
  78. package/sdk-core/core/src/worker/workflow/machines/workflow_task_state_machine.rs +4 -8
  79. package/sdk-core/core/src/worker/workflow/managed_run.rs +75 -45
  80. package/sdk-core/core/src/worker/workflow/mod.rs +104 -55
  81. package/sdk-core/core/src/worker/workflow/run_cache.rs +23 -4
  82. package/sdk-core/core/src/worker/workflow/wft_extraction.rs +4 -4
  83. package/sdk-core/core/src/worker/workflow/wft_poller.rs +3 -3
  84. package/sdk-core/core/src/worker/workflow/workflow_stream.rs +32 -13
  85. package/sdk-core/core-api/Cargo.toml +2 -3
  86. package/sdk-core/core-api/src/errors.rs +22 -20
  87. package/sdk-core/core-api/src/lib.rs +24 -5
  88. package/sdk-core/core-api/src/telemetry/metrics.rs +27 -1
  89. package/sdk-core/core-api/src/telemetry.rs +37 -3
  90. package/sdk-core/core-api/src/worker.rs +36 -3
  91. package/sdk-core/docker/docker-compose-ci.yaml +25 -0
  92. package/sdk-core/etc/otel-collector-ci.yaml +36 -0
  93. package/sdk-core/etc/otel-collector-config.yaml +3 -3
  94. package/sdk-core/etc/prometheus.yaml +1 -1
  95. package/sdk-core/fsm/Cargo.toml +1 -1
  96. package/sdk-core/fsm/rustfsm_procmacro/Cargo.toml +1 -1
  97. package/sdk-core/fsm/rustfsm_procmacro/src/lib.rs +3 -4
  98. package/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/no_handle_conversions_require_into_fail.stderr +1 -1
  99. package/sdk-core/fsm/rustfsm_trait/Cargo.toml +1 -1
  100. package/sdk-core/sdk/Cargo.toml +1 -2
  101. package/sdk-core/sdk/src/activity_context.rs +1 -1
  102. package/sdk-core/sdk/src/interceptors.rs +1 -1
  103. package/sdk-core/sdk/src/lib.rs +126 -54
  104. package/sdk-core/sdk/src/workflow_context/options.rs +184 -74
  105. package/sdk-core/sdk/src/workflow_context.rs +193 -79
  106. package/sdk-core/sdk/src/workflow_future.rs +151 -131
  107. package/sdk-core/sdk-core-protos/Cargo.toml +3 -4
  108. package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/VERSION +1 -1
  109. package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/temporal/api/cloud/account/v1/message.proto +46 -0
  110. package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/temporal/api/cloud/cloudservice/v1/request_response.proto +254 -5
  111. package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/temporal/api/cloud/cloudservice/v1/service.proto +108 -2
  112. package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/temporal/api/cloud/identity/v1/message.proto +94 -15
  113. package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/temporal/api/cloud/namespace/v1/message.proto +102 -4
  114. package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/temporal/api/cloud/nexus/v1/message.proto +84 -0
  115. package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/temporal/api/cloud/operation/v1/message.proto +25 -10
  116. package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/temporal/api/cloud/region/v1/message.proto +14 -1
  117. package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/temporal/api/cloud/resource/v1/message.proto +25 -0
  118. package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/temporal/api/cloud/sink/v1/message.proto +41 -0
  119. package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/temporal/api/cloud/usage/v1/message.proto +59 -0
  120. package/sdk-core/sdk-core-protos/protos/api_upstream/.github/PULL_REQUEST_TEMPLATE.md +2 -0
  121. package/sdk-core/sdk-core-protos/protos/api_upstream/.github/workflows/create-release.yml +135 -0
  122. package/sdk-core/sdk-core-protos/protos/api_upstream/.github/workflows/push-to-buf.yml +20 -0
  123. package/sdk-core/sdk-core-protos/protos/api_upstream/.github/workflows/trigger-api-go-delete-release.yml +13 -0
  124. package/sdk-core/sdk-core-protos/protos/api_upstream/.github/workflows/trigger-api-go-publish-release.yml +13 -0
  125. package/sdk-core/sdk-core-protos/protos/api_upstream/.github/workflows/trigger-api-go-update.yml +13 -21
  126. package/sdk-core/sdk-core-protos/protos/api_upstream/Makefile +2 -2
  127. package/sdk-core/sdk-core-protos/protos/api_upstream/buf.yaml +1 -0
  128. package/sdk-core/sdk-core-protos/protos/api_upstream/openapi/openapiv2.json +3386 -1047
  129. package/sdk-core/sdk-core-protos/protos/api_upstream/openapi/openapiv3.yaml +3529 -1144
  130. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/batch/v1/message.proto +39 -1
  131. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/command/v1/message.proto +6 -0
  132. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/common/v1/message.proto +39 -1
  133. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/deployment/v1/message.proto +252 -0
  134. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/batch_operation.proto +1 -0
  135. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/common.proto +6 -0
  136. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/deployment.proto +96 -0
  137. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/event_type.proto +2 -0
  138. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/failed_cause.proto +2 -0
  139. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/nexus.proto +42 -0
  140. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/reset.proto +2 -0
  141. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/workflow.proto +43 -2
  142. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/errordetails/v1/message.proto +13 -1
  143. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/failure/v1/message.proto +14 -0
  144. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/history/v1/message.proto +70 -12
  145. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/nexus/v1/message.proto +12 -0
  146. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/query/v1/message.proto +9 -2
  147. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/taskqueue/v1/message.proto +46 -2
  148. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/workflow/v1/message.proto +206 -0
  149. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +482 -97
  150. package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +230 -43
  151. package/sdk-core/sdk-core-protos/protos/local/temporal/sdk/core/core_interface.proto +6 -0
  152. package/sdk-core/sdk-core-protos/protos/local/temporal/sdk/core/nexus/nexus.proto +71 -0
  153. package/sdk-core/sdk-core-protos/protos/local/temporal/sdk/core/workflow_activation/workflow_activation.proto +46 -2
  154. package/sdk-core/sdk-core-protos/protos/local/temporal/sdk/core/workflow_commands/workflow_commands.proto +55 -9
  155. package/sdk-core/sdk-core-protos/src/history_builder.rs +5 -5
  156. package/sdk-core/sdk-core-protos/src/history_info.rs +5 -6
  157. package/sdk-core/sdk-core-protos/src/lib.rs +414 -34
  158. package/sdk-core/sdk-core-protos/src/task_token.rs +1 -1
  159. package/sdk-core/test-utils/Cargo.toml +3 -11
  160. package/sdk-core/test-utils/src/canned_histories.rs +1 -1
  161. package/sdk-core/test-utils/src/lib.rs +159 -85
  162. package/sdk-core/tests/fuzzy_workflow.rs +3 -3
  163. package/sdk-core/tests/heavy_tests.rs +3 -3
  164. package/sdk-core/tests/integ_tests/client_tests.rs +171 -20
  165. package/sdk-core/tests/integ_tests/ephemeral_server_tests.rs +45 -39
  166. package/sdk-core/tests/integ_tests/heartbeat_tests.rs +7 -6
  167. package/sdk-core/tests/integ_tests/metrics_tests.rs +492 -35
  168. package/sdk-core/tests/integ_tests/polling_tests.rs +7 -5
  169. package/sdk-core/tests/integ_tests/queries_tests.rs +14 -17
  170. package/sdk-core/tests/integ_tests/update_tests.rs +47 -44
  171. package/sdk-core/tests/integ_tests/visibility_tests.rs +4 -3
  172. package/sdk-core/tests/integ_tests/worker_tests.rs +5 -5
  173. package/sdk-core/tests/integ_tests/workflow_tests/activities.rs +15 -13
  174. package/sdk-core/tests/integ_tests/workflow_tests/cancel_external.rs +28 -14
  175. package/sdk-core/tests/integ_tests/workflow_tests/cancel_wf.rs +7 -1
  176. package/sdk-core/tests/integ_tests/workflow_tests/child_workflows.rs +57 -4
  177. package/sdk-core/tests/integ_tests/workflow_tests/eager.rs +1 -1
  178. package/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +24 -18
  179. package/sdk-core/tests/integ_tests/workflow_tests/nexus.rs +506 -0
  180. package/sdk-core/tests/integ_tests/workflow_tests/patches.rs +1 -1
  181. package/sdk-core/tests/integ_tests/workflow_tests/priority.rs +104 -0
  182. package/sdk-core/tests/integ_tests/workflow_tests/replay.rs +34 -31
  183. package/sdk-core/tests/integ_tests/workflow_tests/resets.rs +1 -1
  184. package/sdk-core/tests/integ_tests/workflow_tests/timers.rs +10 -7
  185. package/sdk-core/tests/integ_tests/workflow_tests.rs +152 -116
  186. package/sdk-core/tests/main.rs +36 -6
  187. package/sdk-core/tests/runner.rs +30 -9
  188. package/src/conversions/slot_supplier_bridge.rs +4 -0
  189. package/src/conversions.rs +1 -0
  190. package/src/worker.rs +5 -7
  191. package/sdk-core/core/src/worker/activities/activity_task_poller_stream.rs +0 -78
@@ -1,17 +1,17 @@
1
1
  mod options;
2
2
 
3
3
  pub use options::{
4
- ActivityOptions, ChildWorkflowOptions, LocalActivityOptions, Signal, SignalData,
5
- SignalWorkflowOptions,
4
+ ActivityOptions, ChildWorkflowOptions, LocalActivityOptions, NexusOperationOptions, Signal,
5
+ SignalData, SignalWorkflowOptions, TimerOptions,
6
6
  };
7
7
 
8
8
  use crate::{
9
- workflow_context::options::IntoWorkflowCommand, CancelExternalWfResult, CancellableID,
10
- CommandCreateRequest, CommandSubscribeChildWorkflowCompletion, IntoUpdateHandlerFunc,
11
- IntoUpdateValidatorFunc, RustWfCmd, SignalExternalWfResult, TimerResult, UnblockEvent,
12
- Unblockable, UpdateFunctions,
9
+ CancelExternalWfResult, CancellableID, CancellableIDWithReason, CommandCreateRequest,
10
+ CommandSubscribeChildWorkflowCompletion, IntoUpdateHandlerFunc, IntoUpdateValidatorFunc,
11
+ NexusStartResult, RustWfCmd, SignalExternalWfResult, SupportsCancelReason, TimerResult,
12
+ UnblockEvent, Unblockable, UpdateFunctions, workflow_context::options::IntoWorkflowCommand,
13
13
  };
14
- use futures_util::{task::Context, FutureExt, Stream, StreamExt};
14
+ use futures_util::{FutureExt, Stream, StreamExt, future::Shared, task::Context};
15
15
  use parking_lot::{RwLock, RwLockReadGuard};
16
16
  use std::{
17
17
  collections::HashMap,
@@ -20,28 +20,34 @@ use std::{
20
20
  ops::Deref,
21
21
  pin::Pin,
22
22
  sync::{
23
+ Arc,
23
24
  atomic::{AtomicBool, Ordering},
24
25
  mpsc::{Receiver, Sender},
25
- Arc,
26
26
  },
27
27
  task::Poll,
28
28
  time::{Duration, SystemTime},
29
29
  };
30
30
  use temporal_sdk_core_protos::{
31
31
  coresdk::{
32
- activity_result::{activity_resolution, ActivityResolution},
32
+ activity_result::{ActivityResolution, activity_resolution},
33
33
  child_workflow::ChildWorkflowResult,
34
34
  common::NamespacedWorkflowExecution,
35
- workflow_activation::resolve_child_workflow_execution_start::Status as ChildWorkflowStartStatus,
35
+ nexus::NexusOperationResult,
36
+ workflow_activation::{
37
+ InitializeWorkflow,
38
+ resolve_child_workflow_execution_start::Status as ChildWorkflowStartStatus,
39
+ },
36
40
  workflow_commands::{
37
- request_cancel_external_workflow_execution as cancel_we,
38
- signal_external_workflow_execution as sig_we, workflow_command,
39
41
  CancelChildWorkflowExecution, ModifyWorkflowProperties,
40
42
  RequestCancelExternalWorkflowExecution, SetPatchMarker,
41
43
  SignalExternalWorkflowExecution, StartTimer, UpsertWorkflowSearchAttributes,
44
+ WorkflowCommand, signal_external_workflow_execution as sig_we, workflow_command,
42
45
  },
43
46
  },
44
- temporal::api::common::v1::{Memo, Payload, SearchAttributes},
47
+ temporal::api::{
48
+ common::v1::{Memo, Payload, SearchAttributes},
49
+ sdk::v1::UserMetadata,
50
+ },
45
51
  };
46
52
  use tokio::sync::{mpsc, oneshot, watch};
47
53
  use tokio_stream::wrappers::UnboundedReceiverStream;
@@ -51,10 +57,10 @@ use tokio_stream::wrappers::UnboundedReceiverStream;
51
57
  pub struct WfContext {
52
58
  namespace: String,
53
59
  task_queue: String,
54
- args: Arc<Vec<Payload>>,
60
+ inital_information: Arc<InitializeWorkflow>,
55
61
 
56
62
  chan: Sender<RustWfCmd>,
57
- am_cancelled: watch::Receiver<bool>,
63
+ am_cancelled: watch::Receiver<Option<String>>,
58
64
  pub(crate) shared: Arc<RwLock<WfContextSharedData>>,
59
65
 
60
66
  seq_nums: Arc<RwLock<WfCtxProtectedDat>>,
@@ -68,8 +74,8 @@ impl WfContext {
68
74
  pub(super) fn new(
69
75
  namespace: String,
70
76
  task_queue: String,
71
- args: Vec<Payload>,
72
- am_cancelled: watch::Receiver<bool>,
77
+ init_workflow_job: InitializeWorkflow,
78
+ am_cancelled: watch::Receiver<Option<String>>,
73
79
  ) -> (Self, Receiver<RustWfCmd>) {
74
80
  // The receiving side is non-async
75
81
  let (chan, rx) = std::sync::mpsc::channel();
@@ -77,16 +83,24 @@ impl WfContext {
77
83
  Self {
78
84
  namespace,
79
85
  task_queue,
80
- args: Arc::new(args),
86
+ shared: Arc::new(RwLock::new(WfContextSharedData {
87
+ random_seed: init_workflow_job.randomness_seed,
88
+ search_attributes: init_workflow_job
89
+ .search_attributes
90
+ .clone()
91
+ .unwrap_or_default(),
92
+ ..Default::default()
93
+ })),
94
+ inital_information: Arc::new(init_workflow_job),
81
95
  chan,
82
96
  am_cancelled,
83
- shared: Arc::new(RwLock::new(Default::default())),
84
97
  seq_nums: Arc::new(RwLock::new(WfCtxProtectedDat {
85
98
  next_timer_sequence_number: 1,
86
99
  next_activity_sequence_number: 1,
87
100
  next_child_workflow_sequence_number: 1,
88
101
  next_cancel_external_wf_sequence_number: 1,
89
102
  next_signal_external_wf_sequence_number: 1,
103
+ next_nexus_op_sequence_number: 1,
90
104
  })),
91
105
  },
92
106
  rx,
@@ -105,7 +119,7 @@ impl WfContext {
105
119
 
106
120
  /// Get the arguments provided to the workflow upon execution start
107
121
  pub fn get_args(&self) -> &[Payload] {
108
- self.args.as_slice()
122
+ self.inital_information.arguments.as_slice()
109
123
  }
110
124
 
111
125
  /// Return the current time according to the workflow (which is not wall-clock time).
@@ -134,33 +148,53 @@ impl WfContext {
134
148
  self.shared.read().random_seed
135
149
  }
136
150
 
137
- /// A future that resolves if/when the workflow is cancelled
138
- pub async fn cancelled(&self) {
139
- if *self.am_cancelled.borrow() {
140
- return;
151
+ /// Return various information that the workflow was initialized with. Will eventually become
152
+ /// a proper non-proto workflow info struct.
153
+ pub fn workflow_initial_info(&self) -> &InitializeWorkflow {
154
+ &self.inital_information
155
+ }
156
+
157
+ /// A future that resolves if/when the workflow is cancelled, with the user provided cause
158
+ pub async fn cancelled(&self) -> String {
159
+ if let Some(s) = self.am_cancelled.borrow().as_ref() {
160
+ return s.clone();
141
161
  }
142
162
  self.am_cancelled
143
163
  .clone()
144
164
  .changed()
145
165
  .await
146
166
  .expect("Cancelled send half not dropped");
167
+ self.am_cancelled
168
+ .borrow()
169
+ .as_ref()
170
+ .cloned()
171
+ .unwrap_or_default()
147
172
  }
148
173
 
149
174
  /// Request to create a timer
150
- pub fn timer(&self, duration: Duration) -> impl CancellableFuture<TimerResult> {
175
+ pub fn timer<T: Into<TimerOptions>>(&self, opts: T) -> impl CancellableFuture<TimerResult> {
176
+ let opts: TimerOptions = opts.into();
151
177
  let seq = self.seq_nums.write().next_timer_seq();
152
178
  let (cmd, unblocker) = CancellableWFCommandFut::new(CancellableID::Timer(seq));
153
179
  self.send(
154
180
  CommandCreateRequest {
155
- cmd: StartTimer {
156
- seq,
157
- start_to_fire_timeout: Some(
158
- duration
159
- .try_into()
160
- .expect("Durations must fit into 64 bits"),
181
+ cmd: WorkflowCommand {
182
+ variant: Some(
183
+ StartTimer {
184
+ seq,
185
+ start_to_fire_timeout: Some(
186
+ opts.duration
187
+ .try_into()
188
+ .expect("Durations must fit into 64 bits"),
189
+ ),
190
+ }
191
+ .into(),
161
192
  ),
162
- }
163
- .into(),
193
+ user_metadata: Some(UserMetadata {
194
+ summary: opts.summary.map(|x| x.as_bytes().into()),
195
+ details: None,
196
+ }),
197
+ },
164
198
  unblocker,
165
199
  }
166
200
  .into(),
@@ -180,7 +214,7 @@ impl WfContext {
180
214
  let (cmd, unblocker) = CancellableWFCommandFut::new(CancellableID::Activity(seq));
181
215
  self.send(
182
216
  CommandCreateRequest {
183
- cmd: opts.into_command(seq).into(),
217
+ cmd: opts.into_command(seq),
184
218
  unblocker,
185
219
  }
186
220
  .into(),
@@ -205,7 +239,7 @@ impl WfContext {
205
239
  let (cmd, unblocker) = CancellableWFCommandFut::new(CancellableID::LocalActivity(seq));
206
240
  self.send(
207
241
  CommandCreateRequest {
208
- cmd: opts.into_command(seq).into(),
242
+ cmd: opts.into_command(seq),
209
243
  unblocker,
210
244
  }
211
245
  .into(),
@@ -308,17 +342,23 @@ impl WfContext {
308
342
  pub fn cancel_external(
309
343
  &self,
310
344
  target: NamespacedWorkflowExecution,
345
+ reason: String,
311
346
  ) -> impl Future<Output = CancelExternalWfResult> {
312
- let target = cancel_we::Target::WorkflowExecution(target);
313
347
  let seq = self.seq_nums.write().next_cancel_external_wf_seq();
314
348
  let (cmd, unblocker) = WFCommandFut::new();
315
349
  self.send(
316
350
  CommandCreateRequest {
317
- cmd: RequestCancelExternalWorkflowExecution {
318
- seq,
319
- target: Some(target),
320
- }
321
- .into(),
351
+ cmd: WorkflowCommand {
352
+ variant: Some(
353
+ RequestCancelExternalWorkflowExecution {
354
+ seq,
355
+ workflow_execution: Some(target),
356
+ reason,
357
+ }
358
+ .into(),
359
+ ),
360
+ user_metadata: None,
361
+ },
322
362
  unblocker,
323
363
  }
324
364
  .into(),
@@ -344,6 +384,31 @@ impl WfContext {
344
384
  ))
345
385
  }
346
386
 
387
+ /// Start a nexus operation
388
+ pub fn start_nexus_operation(
389
+ &self,
390
+ opts: NexusOperationOptions,
391
+ ) -> impl CancellableFuture<NexusStartResult> {
392
+ let seq = self.seq_nums.write().next_nexus_op_seq();
393
+ let (result_future, unblocker) = WFCommandFut::new();
394
+ self.send(RustWfCmd::SubscribeNexusOperationCompletion { seq, unblocker });
395
+ let (cmd, unblocker) = CancellableWFCommandFut::new_with_dat(
396
+ CancellableID::NexusOp(seq),
397
+ NexusUnblockData {
398
+ result_future: result_future.shared(),
399
+ schedule_seq: seq,
400
+ },
401
+ );
402
+ self.send(
403
+ CommandCreateRequest {
404
+ cmd: opts.into_command(seq),
405
+ unblocker,
406
+ }
407
+ .into(),
408
+ );
409
+ cmd
410
+ }
411
+
347
412
  /// Buffer a command to be sent in the activation reply
348
413
  pub(crate) fn send(&self, c: RustWfCmd) {
349
414
  self.chan.send(c).expect("command channel intact");
@@ -359,14 +424,19 @@ impl WfContext {
359
424
  CancellableWFCommandFut::new(CancellableID::SignalExternalWorkflow(seq));
360
425
  self.send(
361
426
  CommandCreateRequest {
362
- cmd: SignalExternalWorkflowExecution {
363
- seq,
364
- signal_name: signal.signal_name,
365
- args: signal.data.input,
366
- target: Some(target),
367
- headers: signal.data.headers,
368
- }
369
- .into(),
427
+ cmd: WorkflowCommand {
428
+ variant: Some(
429
+ SignalExternalWorkflowExecution {
430
+ seq,
431
+ signal_name: signal.signal_name,
432
+ args: signal.data.input,
433
+ target: Some(target),
434
+ headers: signal.data.headers,
435
+ }
436
+ .into(),
437
+ ),
438
+ user_metadata: None,
439
+ },
370
440
  unblocker,
371
441
  }
372
442
  .into(),
@@ -386,6 +456,7 @@ struct WfCtxProtectedDat {
386
456
  next_child_workflow_sequence_number: u32,
387
457
  next_cancel_external_wf_sequence_number: u32,
388
458
  next_signal_external_wf_sequence_number: u32,
459
+ next_nexus_op_sequence_number: u32,
389
460
  }
390
461
 
391
462
  impl WfCtxProtectedDat {
@@ -414,6 +485,11 @@ impl WfCtxProtectedDat {
414
485
  self.next_signal_external_wf_sequence_number += 1;
415
486
  seq
416
487
  }
488
+ fn next_nexus_op_seq(&mut self) -> u32 {
489
+ let seq = self.next_nexus_op_sequence_number;
490
+ self.next_nexus_op_sequence_number += 1;
491
+ seq
492
+ }
417
493
  }
418
494
 
419
495
  #[derive(Clone, Debug, Default)]
@@ -466,6 +542,12 @@ pub trait CancellableFuture<T>: Future<Output = T> {
466
542
  fn cancel(&self, cx: &WfContext);
467
543
  }
468
544
 
545
+ /// A Future that can be cancelled with a reason
546
+ pub trait CancellableFutureWithReason<T>: CancellableFuture<T> {
547
+ /// Cancel this Future with a reason
548
+ fn cancel_with_reason(&self, cx: &WfContext, reason: String);
549
+ }
550
+
469
551
  struct WFCommandFut<T, D> {
470
552
  _unused: PhantomData<T>,
471
553
  result_rx: oneshot::Receiver<UnblockEvent>,
@@ -511,20 +593,17 @@ where
511
593
  }
512
594
  }
513
595
 
514
- struct CancellableWFCommandFut<T, D> {
596
+ struct CancellableWFCommandFut<T, D, ID = CancellableID> {
515
597
  cmd_fut: WFCommandFut<T, D>,
516
- cancellable_id: CancellableID,
598
+ cancellable_id: ID,
517
599
  }
518
- impl<T> CancellableWFCommandFut<T, ()> {
519
- fn new(cancellable_id: CancellableID) -> (Self, oneshot::Sender<UnblockEvent>) {
600
+ impl<T, ID> CancellableWFCommandFut<T, (), ID> {
601
+ fn new(cancellable_id: ID) -> (Self, oneshot::Sender<UnblockEvent>) {
520
602
  Self::new_with_dat(cancellable_id, ())
521
603
  }
522
604
  }
523
- impl<T, D> CancellableWFCommandFut<T, D> {
524
- fn new_with_dat(
525
- cancellable_id: CancellableID,
526
- other_dat: D,
527
- ) -> (Self, oneshot::Sender<UnblockEvent>) {
605
+ impl<T, D, ID> CancellableWFCommandFut<T, D, ID> {
606
+ fn new_with_dat(cancellable_id: ID, other_dat: D) -> (Self, oneshot::Sender<UnblockEvent>) {
528
607
  let (cmd_fut, sender) = WFCommandFut::new_with_dat(other_dat);
529
608
  (
530
609
  Self {
@@ -535,8 +614,8 @@ impl<T, D> CancellableWFCommandFut<T, D> {
535
614
  )
536
615
  }
537
616
  }
538
- impl<T, D> Unpin for CancellableWFCommandFut<T, D> where T: Unblockable<OtherDat = D> {}
539
- impl<T, D> Future for CancellableWFCommandFut<T, D>
617
+ impl<T, D, ID> Unpin for CancellableWFCommandFut<T, D, ID> where T: Unblockable<OtherDat = D> {}
618
+ impl<T, D, ID> Future for CancellableWFCommandFut<T, D, ID>
540
619
  where
541
620
  T: Unblockable<OtherDat = D>,
542
621
  {
@@ -547,12 +626,22 @@ where
547
626
  }
548
627
  }
549
628
 
550
- impl<T, D> CancellableFuture<T> for CancellableWFCommandFut<T, D>
629
+ impl<T, D, ID> CancellableFuture<T> for CancellableWFCommandFut<T, D, ID>
551
630
  where
552
631
  T: Unblockable<OtherDat = D>,
632
+ ID: Clone + Into<CancellableID>,
553
633
  {
554
634
  fn cancel(&self, cx: &WfContext) {
555
- cx.cancel(self.cancellable_id.clone());
635
+ cx.cancel(self.cancellable_id.clone().into());
636
+ }
637
+ }
638
+ impl<T, D> CancellableFutureWithReason<T> for CancellableWFCommandFut<T, D, CancellableIDWithReason>
639
+ where
640
+ T: Unblockable<OtherDat = D>,
641
+ {
642
+ fn cancel_with_reason(&self, cx: &WfContext, reason: String) {
643
+ let new_id = self.cancellable_id.clone().with_reason(reason);
644
+ cx.cancel(new_id);
556
645
  }
557
646
  }
558
647
 
@@ -578,8 +667,8 @@ impl<'a> LATimerBackoffFut<'a> {
578
667
  }
579
668
  }
580
669
  }
581
- impl<'a> Unpin for LATimerBackoffFut<'a> {}
582
- impl<'a> Future for LATimerBackoffFut<'a> {
670
+ impl Unpin for LATimerBackoffFut<'_> {}
671
+ impl Future for LATimerBackoffFut<'_> {
583
672
  type Output = ActivityResolution;
584
673
 
585
674
  fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
@@ -619,7 +708,7 @@ impl<'a> Future for LATimerBackoffFut<'a> {
619
708
  });
620
709
  }
621
710
 
622
- let timer_f = self.ctx.timer(
711
+ let timer_f = self.ctx.timer::<Duration>(
623
712
  b.backoff_duration
624
713
  .expect("Duration is set")
625
714
  .try_into()
@@ -634,7 +723,7 @@ impl<'a> Future for LATimerBackoffFut<'a> {
634
723
  poll_res
635
724
  }
636
725
  }
637
- impl<'a> CancellableFuture<ActivityResolution> for LATimerBackoffFut<'a> {
726
+ impl CancellableFuture<ActivityResolution> for LATimerBackoffFut<'_> {
638
727
  fn cancel(&self, ctx: &WfContext) {
639
728
  self.did_cancel.store(true, Ordering::Release);
640
729
  if let Some(tf) = self.timer_fut.as_ref() {
@@ -652,7 +741,7 @@ pub struct ChildWorkflow {
652
741
 
653
742
  pub(crate) struct ChildWfCommon {
654
743
  workflow_id: String,
655
- result_future: CancellableWFCommandFut<ChildWorkflowResult, ()>,
744
+ result_future: CancellableWFCommandFut<ChildWorkflowResult, (), CancellableIDWithReason>,
656
745
  }
657
746
 
658
747
  /// Child workflow in pending state
@@ -685,20 +774,19 @@ pub struct StartedChildWorkflow {
685
774
 
686
775
  impl ChildWorkflow {
687
776
  /// Start the child workflow, the returned Future is cancellable.
688
- pub fn start(self, cx: &WfContext) -> impl CancellableFuture<PendingChildWorkflow> {
777
+ pub fn start(self, cx: &WfContext) -> impl CancellableFutureWithReason<PendingChildWorkflow> {
689
778
  let child_seq = cx.seq_nums.write().next_child_workflow_seq();
690
779
  // Immediately create the command/future for the result, otherwise if the user does
691
780
  // not await the result until *after* we receive an activation for it, there will be nothing
692
781
  // to match when unblocking.
693
782
  let cancel_seq = cx.seq_nums.write().next_cancel_external_wf_seq();
694
783
  let (result_cmd, unblocker) =
695
- CancellableWFCommandFut::new(CancellableID::ExternalWorkflow {
784
+ CancellableWFCommandFut::new(CancellableIDWithReason::ExternalWorkflow {
696
785
  seqnum: cancel_seq,
697
786
  execution: NamespacedWorkflowExecution {
698
787
  workflow_id: self.opts.workflow_id.clone(),
699
788
  ..Default::default()
700
789
  },
701
- only_child: true,
702
790
  });
703
791
  cx.send(
704
792
  CommandSubscribeChildWorkflowCompletion {
@@ -713,11 +801,13 @@ impl ChildWorkflow {
713
801
  result_future: result_cmd,
714
802
  };
715
803
 
716
- let (cmd, unblocker) =
717
- CancellableWFCommandFut::new_with_dat(CancellableID::ChildWorkflow(child_seq), common);
804
+ let (cmd, unblocker) = CancellableWFCommandFut::new_with_dat(
805
+ CancellableIDWithReason::ChildWorkflow { seqnum: child_seq },
806
+ common,
807
+ );
718
808
  cx.send(
719
809
  CommandCreateRequest {
720
- cmd: self.opts.into_command(child_seq).into(),
810
+ cmd: self.opts.into_command(child_seq),
721
811
  unblocker,
722
812
  }
723
813
  .into(),
@@ -730,27 +820,51 @@ impl ChildWorkflow {
730
820
  impl StartedChildWorkflow {
731
821
  /// Consumes self and returns a future that will wait until completion of this child workflow
732
822
  /// execution
733
- pub fn result(self) -> impl CancellableFuture<ChildWorkflowResult> {
823
+ pub fn result(self) -> impl CancellableFutureWithReason<ChildWorkflowResult> {
734
824
  self.common.result_future
735
825
  }
736
826
 
737
827
  /// Cancel the child workflow
738
- pub fn cancel(&self, cx: &WfContext) {
828
+ pub fn cancel(&self, cx: &WfContext, reason: String) {
739
829
  cx.send(RustWfCmd::NewNonblockingCmd(
740
830
  CancelChildWorkflowExecution {
741
831
  child_workflow_seq: self.common.result_future.cancellable_id.seq_num(),
832
+ reason,
742
833
  }
743
834
  .into(),
744
835
  ));
745
836
  }
746
837
 
747
838
  /// Signal the child workflow
748
- pub fn signal(
839
+ pub fn signal<'a, S: Into<Signal>>(
749
840
  &self,
750
- cx: &WfContext,
751
- data: impl Into<Signal>,
752
- ) -> impl CancellableFuture<SignalExternalWfResult> {
841
+ cx: &'a WfContext,
842
+ data: S,
843
+ ) -> impl CancellableFuture<SignalExternalWfResult> + use<'a, S> {
753
844
  let target = sig_we::Target::ChildWorkflowId(self.common.workflow_id.clone());
754
845
  cx.send_signal_wf(target, data.into())
755
846
  }
756
847
  }
848
+
849
+ #[derive(derive_more::Debug)]
850
+ #[debug("StartedNexusOperation{{ operation_id: {operation_id:?} }}")]
851
+ pub struct StartedNexusOperation {
852
+ /// The operation id, if the operation started asynchronously
853
+ pub operation_id: Option<String>,
854
+ pub(crate) unblock_dat: NexusUnblockData,
855
+ }
856
+
857
+ pub(crate) struct NexusUnblockData {
858
+ result_future: Shared<WFCommandFut<NexusOperationResult, ()>>,
859
+ schedule_seq: u32,
860
+ }
861
+
862
+ impl StartedNexusOperation {
863
+ pub async fn result(&self) -> NexusOperationResult {
864
+ self.unblock_dat.result_future.clone().await
865
+ }
866
+
867
+ pub fn cancel(&self, cx: &WfContext) {
868
+ cx.cancel(CancellableID::NexusOp(self.unblock_dat.schedule_seq));
869
+ }
870
+ }