@temporalio/core-bridge 1.8.5 → 1.9.0-rc.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 (196) hide show
  1. package/Cargo.lock +189 -152
  2. package/Cargo.toml +1 -0
  3. package/lib/index.d.ts +17 -44
  4. package/lib/index.js.map +1 -1
  5. package/package.json +3 -4
  6. package/releases/aarch64-apple-darwin/index.node +0 -0
  7. package/releases/aarch64-unknown-linux-gnu/index.node +0 -0
  8. package/releases/x86_64-apple-darwin/index.node +0 -0
  9. package/releases/x86_64-pc-windows-msvc/index.node +0 -0
  10. package/releases/x86_64-unknown-linux-gnu/index.node +0 -0
  11. package/sdk-core/.github/workflows/heavy.yml +4 -0
  12. package/sdk-core/.github/workflows/per-pr.yml +96 -0
  13. package/sdk-core/ARCHITECTURE.md +1 -1
  14. package/sdk-core/Cargo.toml +6 -0
  15. package/sdk-core/README.md +37 -21
  16. package/sdk-core/client/Cargo.toml +6 -3
  17. package/sdk-core/client/src/lib.rs +272 -138
  18. package/sdk-core/client/src/metrics.rs +68 -57
  19. package/sdk-core/client/src/raw.rs +191 -45
  20. package/sdk-core/client/src/retry.rs +20 -0
  21. package/sdk-core/client/src/worker_registry/mod.rs +264 -0
  22. package/sdk-core/client/src/workflow_handle/mod.rs +2 -1
  23. package/sdk-core/core/Cargo.toml +16 -18
  24. package/sdk-core/core/src/core_tests/child_workflows.rs +7 -7
  25. package/sdk-core/core/src/core_tests/mod.rs +1 -0
  26. package/sdk-core/core/src/core_tests/replay_flag.rs +29 -39
  27. package/sdk-core/core/src/core_tests/updates.rs +73 -0
  28. package/sdk-core/core/src/core_tests/workflow_tasks.rs +52 -1
  29. package/sdk-core/core/src/ephemeral_server/mod.rs +34 -11
  30. package/sdk-core/core/src/internal_flags.rs +7 -1
  31. package/sdk-core/core/src/lib.rs +19 -36
  32. package/sdk-core/core/src/protosext/mod.rs +11 -3
  33. package/sdk-core/core/src/protosext/protocol_messages.rs +102 -0
  34. package/sdk-core/core/src/replay/mod.rs +100 -48
  35. package/sdk-core/core/src/telemetry/log_export.rs +161 -28
  36. package/sdk-core/core/src/telemetry/metrics.rs +869 -248
  37. package/sdk-core/core/src/telemetry/mod.rs +135 -239
  38. package/sdk-core/core/src/telemetry/prometheus_server.rs +36 -31
  39. package/sdk-core/core/src/test_help/mod.rs +63 -4
  40. package/sdk-core/core/src/worker/activities/activity_heartbeat_manager.rs +12 -2
  41. package/sdk-core/core/src/worker/activities.rs +276 -10
  42. package/sdk-core/core/src/worker/client/mocks.rs +18 -0
  43. package/sdk-core/core/src/worker/client.rs +16 -3
  44. package/sdk-core/core/src/worker/mod.rs +50 -19
  45. package/sdk-core/core/src/worker/slot_provider.rs +175 -0
  46. package/sdk-core/core/src/worker/workflow/driven_workflow.rs +27 -34
  47. package/sdk-core/core/src/worker/workflow/history_update.rs +4 -1
  48. package/sdk-core/core/src/worker/workflow/machines/activity_state_machine.rs +36 -94
  49. package/sdk-core/core/src/worker/workflow/machines/cancel_external_state_machine.rs +34 -22
  50. package/sdk-core/core/src/worker/workflow/machines/cancel_workflow_state_machine.rs +50 -34
  51. package/sdk-core/core/src/worker/workflow/machines/child_workflow_state_machine.rs +106 -92
  52. package/sdk-core/core/src/worker/workflow/machines/continue_as_new_workflow_state_machine.rs +22 -21
  53. package/sdk-core/core/src/worker/workflow/machines/local_activity_state_machine.rs +386 -499
  54. package/sdk-core/core/src/worker/workflow/machines/mod.rs +12 -2
  55. package/sdk-core/core/src/worker/workflow/machines/modify_workflow_properties_state_machine.rs +33 -26
  56. package/sdk-core/core/src/worker/workflow/machines/patch_state_machine.rs +198 -215
  57. package/sdk-core/core/src/worker/workflow/machines/signal_external_state_machine.rs +66 -62
  58. package/sdk-core/core/src/worker/workflow/machines/timer_state_machine.rs +88 -119
  59. package/sdk-core/core/src/worker/workflow/machines/transition_coverage.rs +3 -1
  60. package/sdk-core/core/src/worker/workflow/machines/update_state_machine.rs +411 -0
  61. package/sdk-core/core/src/worker/workflow/machines/upsert_search_attributes_state_machine.rs +26 -25
  62. package/sdk-core/core/src/worker/workflow/machines/workflow_machines.rs +302 -85
  63. package/sdk-core/core/src/worker/workflow/managed_run.rs +179 -132
  64. package/sdk-core/core/src/worker/workflow/mod.rs +121 -46
  65. package/sdk-core/core/src/worker/workflow/run_cache.rs +8 -12
  66. package/sdk-core/core/src/worker/workflow/workflow_stream.rs +45 -38
  67. package/sdk-core/core-api/Cargo.toml +7 -6
  68. package/sdk-core/core-api/src/lib.rs +4 -12
  69. package/sdk-core/core-api/src/telemetry/metrics.rs +334 -0
  70. package/sdk-core/core-api/src/telemetry.rs +53 -42
  71. package/sdk-core/core-api/src/worker.rs +7 -0
  72. package/sdk-core/{.buildkite/docker → docker}/docker-compose.yaml +1 -1
  73. package/sdk-core/etc/dynamic-config.yaml +11 -1
  74. package/sdk-core/fsm/rustfsm_procmacro/Cargo.toml +1 -1
  75. package/sdk-core/fsm/rustfsm_procmacro/src/lib.rs +1 -3
  76. package/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/no_handle_conversions_require_into_fail.stderr +2 -2
  77. package/sdk-core/sdk/Cargo.toml +1 -1
  78. package/sdk-core/sdk/src/lib.rs +85 -7
  79. package/sdk-core/sdk/src/workflow_context/options.rs +4 -0
  80. package/sdk-core/sdk/src/workflow_context.rs +43 -15
  81. package/sdk-core/sdk/src/workflow_future.rs +334 -204
  82. package/sdk-core/sdk-core-protos/Cargo.toml +2 -2
  83. package/sdk-core/sdk-core-protos/build.rs +14 -14
  84. package/sdk-core/sdk-core-protos/protos/api_upstream/.buildkite/Dockerfile +2 -0
  85. package/sdk-core/sdk-core-protos/protos/api_upstream/Makefile +99 -0
  86. package/sdk-core/sdk-core-protos/protos/api_upstream/api-linter.yaml +56 -0
  87. package/sdk-core/sdk-core-protos/protos/api_upstream/buf.gen.yaml +20 -0
  88. package/sdk-core/sdk-core-protos/protos/api_upstream/buf.lock +11 -0
  89. package/sdk-core/sdk-core-protos/protos/api_upstream/buf.yaml +18 -0
  90. package/sdk-core/sdk-core-protos/protos/api_upstream/google/api/annotations.proto +31 -0
  91. package/sdk-core/sdk-core-protos/protos/api_upstream/google/api/http.proto +379 -0
  92. package/sdk-core/sdk-core-protos/protos/api_upstream/google/protobuf/any.proto +162 -0
  93. package/sdk-core/sdk-core-protos/protos/api_upstream/google/protobuf/descriptor.proto +1212 -0
  94. package/sdk-core/sdk-core-protos/protos/api_upstream/google/protobuf/duration.proto +115 -0
  95. package/sdk-core/sdk-core-protos/protos/api_upstream/google/protobuf/empty.proto +51 -0
  96. package/sdk-core/sdk-core-protos/protos/api_upstream/google/protobuf/timestamp.proto +144 -0
  97. package/sdk-core/sdk-core-protos/protos/api_upstream/google/protobuf/wrappers.proto +123 -0
  98. package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/batch/v1/message.proto +3 -5
  99. package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/command/v1/message.proto +11 -13
  100. package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/common/v1/message.proto +2 -4
  101. package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/enums/v1/failed_cause.proto +2 -0
  102. package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/enums/v1/reset.proto +1 -1
  103. package/sdk-core/{protos/api_upstream/build/tools.go → sdk-core-protos/protos/api_upstream/temporal/api/export/v1/message.proto} +22 -6
  104. package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/filter/v1/message.proto +2 -4
  105. package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/history/v1/message.proto +21 -23
  106. package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/namespace/v1/message.proto +2 -4
  107. package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/operatorservice/v1/request_response.proto +2 -0
  108. package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/operatorservice/v1/service.proto +4 -0
  109. package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/replication/v1/message.proto +1 -3
  110. package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/schedule/v1/message.proto +36 -20
  111. package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/sdk/v1/task_complete_metadata.proto +13 -0
  112. package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/taskqueue/v1/message.proto +2 -4
  113. package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/update/v1/message.proto +1 -1
  114. package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/version/v1/message.proto +2 -3
  115. package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/workflow/v1/message.proto +18 -20
  116. package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/workflowservice/v1/request_response.proto +84 -32
  117. package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/workflowservice/v1/service.proto +205 -47
  118. package/sdk-core/{protos → sdk-core-protos/protos}/local/temporal/sdk/core/workflow_activation/workflow_activation.proto +57 -0
  119. package/sdk-core/{protos → sdk-core-protos/protos}/local/temporal/sdk/core/workflow_commands/workflow_commands.proto +27 -0
  120. package/sdk-core/sdk-core-protos/src/history_builder.rs +67 -2
  121. package/sdk-core/sdk-core-protos/src/lib.rs +75 -2
  122. package/sdk-core/sdk-core-protos/src/utilities.rs +14 -0
  123. package/sdk-core/test-utils/Cargo.toml +5 -1
  124. package/sdk-core/test-utils/src/canned_histories.rs +3 -57
  125. package/sdk-core/test-utils/src/interceptors.rs +46 -0
  126. package/sdk-core/test-utils/src/lib.rs +106 -38
  127. package/sdk-core/tests/integ_tests/metrics_tests.rs +110 -15
  128. package/sdk-core/tests/integ_tests/queries_tests.rs +174 -3
  129. package/sdk-core/tests/integ_tests/update_tests.rs +908 -0
  130. package/sdk-core/tests/integ_tests/workflow_tests/activities.rs +44 -1
  131. package/sdk-core/tests/integ_tests/workflow_tests/cancel_external.rs +1 -1
  132. package/sdk-core/tests/integ_tests/workflow_tests/cancel_wf.rs +1 -1
  133. package/sdk-core/tests/integ_tests/workflow_tests/child_workflows.rs +4 -4
  134. package/sdk-core/tests/integ_tests/workflow_tests/eager.rs +61 -0
  135. package/sdk-core/tests/integ_tests/workflow_tests/replay.rs +27 -2
  136. package/sdk-core/tests/integ_tests/workflow_tests.rs +1 -0
  137. package/sdk-core/tests/main.rs +2 -1
  138. package/sdk-core/tests/runner.rs +15 -2
  139. package/src/conversions.rs +75 -89
  140. package/src/helpers.rs +74 -0
  141. package/src/runtime.rs +17 -6
  142. package/src/worker.rs +14 -61
  143. package/ts/index.ts +21 -52
  144. package/sdk-core/.buildkite/docker/Dockerfile +0 -9
  145. package/sdk-core/.buildkite/docker/build.sh +0 -5
  146. package/sdk-core/.buildkite/docker/docker-compose-ci.yaml +0 -27
  147. package/sdk-core/.buildkite/pipeline.yml +0 -57
  148. package/sdk-core/.github/workflows/semgrep.yml +0 -25
  149. package/sdk-core/core/src/worker/workflow/bridge.rs +0 -35
  150. package/sdk-core/core/src/worker/workflow/managed_run/managed_wf_test.rs +0 -215
  151. package/sdk-core/protos/api_upstream/.buildkite/Dockerfile +0 -2
  152. package/sdk-core/protos/api_upstream/Makefile +0 -80
  153. package/sdk-core/protos/api_upstream/api-linter.yaml +0 -40
  154. package/sdk-core/protos/api_upstream/buf.yaml +0 -9
  155. package/sdk-core/protos/api_upstream/build/go.mod +0 -7
  156. package/sdk-core/protos/api_upstream/build/go.sum +0 -5
  157. package/sdk-core/protos/api_upstream/go.mod +0 -6
  158. package/sdk-core/protos/testsrv_upstream/dependencies/gogoproto/gogo.proto +0 -141
  159. /package/sdk-core/{.buildkite/docker → docker}/docker-compose-telem.yaml +0 -0
  160. /package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/.buildkite/docker-compose.yml +0 -0
  161. /package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/.buildkite/pipeline.yml +0 -0
  162. /package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/.github/CODEOWNERS +0 -0
  163. /package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/.github/PULL_REQUEST_TEMPLATE.md +0 -0
  164. /package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/.github/workflows/publish-docs.yml +0 -0
  165. /package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/.github/workflows/trigger-api-go-update.yml +0 -0
  166. /package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/LICENSE +0 -0
  167. /package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/README.md +0 -0
  168. /package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/enums/v1/batch_operation.proto +0 -0
  169. /package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/enums/v1/command_type.proto +0 -0
  170. /package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/enums/v1/common.proto +0 -0
  171. /package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/enums/v1/event_type.proto +0 -0
  172. /package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/enums/v1/namespace.proto +0 -0
  173. /package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/enums/v1/query.proto +0 -0
  174. /package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/enums/v1/schedule.proto +0 -0
  175. /package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/enums/v1/task_queue.proto +0 -0
  176. /package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/enums/v1/update.proto +0 -0
  177. /package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/enums/v1/workflow.proto +0 -0
  178. /package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/errordetails/v1/message.proto +0 -0
  179. /package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/failure/v1/message.proto +0 -0
  180. /package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/protocol/v1/message.proto +0 -0
  181. /package/sdk-core/{protos → sdk-core-protos/protos}/api_upstream/temporal/api/query/v1/message.proto +0 -0
  182. /package/sdk-core/{protos → sdk-core-protos/protos}/google/rpc/status.proto +0 -0
  183. /package/sdk-core/{protos → sdk-core-protos/protos}/grpc/health/v1/health.proto +0 -0
  184. /package/sdk-core/{protos → sdk-core-protos/protos}/local/temporal/sdk/core/activity_result/activity_result.proto +0 -0
  185. /package/sdk-core/{protos → sdk-core-protos/protos}/local/temporal/sdk/core/activity_task/activity_task.proto +0 -0
  186. /package/sdk-core/{protos → sdk-core-protos/protos}/local/temporal/sdk/core/child_workflow/child_workflow.proto +0 -0
  187. /package/sdk-core/{protos → sdk-core-protos/protos}/local/temporal/sdk/core/common/common.proto +0 -0
  188. /package/sdk-core/{protos → sdk-core-protos/protos}/local/temporal/sdk/core/core_interface.proto +0 -0
  189. /package/sdk-core/{protos → sdk-core-protos/protos}/local/temporal/sdk/core/external_data/external_data.proto +0 -0
  190. /package/sdk-core/{protos → sdk-core-protos/protos}/local/temporal/sdk/core/workflow_completion/workflow_completion.proto +0 -0
  191. /package/sdk-core/{protos → sdk-core-protos/protos}/testsrv_upstream/Makefile +0 -0
  192. /package/sdk-core/{protos → sdk-core-protos/protos}/testsrv_upstream/api-linter.yaml +0 -0
  193. /package/sdk-core/{protos → sdk-core-protos/protos}/testsrv_upstream/buf.yaml +0 -0
  194. /package/sdk-core/{protos/api_upstream → sdk-core-protos/protos/testsrv_upstream}/dependencies/gogoproto/gogo.proto +0 -0
  195. /package/sdk-core/{protos → sdk-core-protos/protos}/testsrv_upstream/temporal/api/testservice/v1/request_response.proto +0 -0
  196. /package/sdk-core/{protos → sdk-core-protos/protos}/testsrv_upstream/temporal/api/testservice/v1/service.proto +0 -0
@@ -55,13 +55,11 @@ pub use activity_context::ActContext;
55
55
  pub use temporal_client::Namespace;
56
56
  pub use workflow_context::{
57
57
  ActivityOptions, CancellableFuture, ChildWorkflow, ChildWorkflowOptions, LocalActivityOptions,
58
- Signal, SignalData, SignalWorkflowOptions, WfContext,
58
+ PendingChildWorkflow, Signal, SignalData, SignalWorkflowOptions, StartedChildWorkflow,
59
+ WfContext,
59
60
  };
60
61
 
61
- use crate::{
62
- interceptors::WorkerInterceptor,
63
- workflow_context::{ChildWfCommon, PendingChildWorkflow},
64
- };
62
+ use crate::{interceptors::WorkerInterceptor, workflow_context::ChildWfCommon};
65
63
  use anyhow::{anyhow, bail, Context};
66
64
  use app_data::AppData;
67
65
  use futures::{future::BoxFuture, FutureExt, StreamExt, TryFutureExt, TryStreamExt};
@@ -342,8 +340,8 @@ impl Worker {
342
340
  }
343
341
 
344
342
  /// Set a [WorkerInterceptor]
345
- pub fn set_worker_interceptor(&mut self, interceptor: Box<dyn WorkerInterceptor>) {
346
- self.common.worker_interceptor = Some(interceptor);
343
+ pub fn set_worker_interceptor(&mut self, interceptor: impl WorkerInterceptor + 'static) {
344
+ self.common.worker_interceptor = Some(Box::new(interceptor));
347
345
  }
348
346
 
349
347
  /// Turns this rust worker into a new worker with all the same workflows and activities
@@ -685,6 +683,7 @@ enum RustWfCmd {
685
683
  NewNonblockingCmd(workflow_command::Variant),
686
684
  SubscribeChildWorkflowCompletion(CommandSubscribeChildWorkflowCompletion),
687
685
  SubscribeSignal(String, UnboundedSender<SignalData>),
686
+ RegisterUpdate(String, UpdateFunctions),
688
687
  }
689
688
 
690
689
  struct CommandCreateRequest {
@@ -861,6 +860,85 @@ where
861
860
  }
862
861
  }
863
862
 
863
+ /// Extra information attached to workflow updates
864
+ #[derive(Clone)]
865
+ pub struct UpdateInfo {
866
+ /// The update's id, unique within the workflow
867
+ pub update_id: String,
868
+ /// Headers attached to the update
869
+ pub headers: HashMap<String, Payload>,
870
+ }
871
+
872
+ /// Context for a workflow update
873
+ pub struct UpdateContext {
874
+ /// The workflow context, can be used to do normal workflow things inside the update handler
875
+ pub wf_ctx: WfContext,
876
+ /// Additional update info
877
+ pub info: UpdateInfo,
878
+ }
879
+
880
+ struct UpdateFunctions {
881
+ validator: BoxUpdateValidatorFn,
882
+ handler: BoxUpdateHandlerFn,
883
+ }
884
+
885
+ impl UpdateFunctions {
886
+ pub(crate) fn new<Arg, Res>(
887
+ v: impl IntoUpdateValidatorFunc<Arg> + Sized,
888
+ h: impl IntoUpdateHandlerFunc<Arg, Res> + Sized,
889
+ ) -> Self {
890
+ Self {
891
+ validator: v.into_update_validator_fn(),
892
+ handler: h.into_update_handler_fn(),
893
+ }
894
+ }
895
+ }
896
+
897
+ type BoxUpdateValidatorFn = Box<dyn Fn(&UpdateInfo, &Payload) -> Result<(), anyhow::Error> + Send>;
898
+ /// Closures / functions which can be turned into update validation functions implement this trait
899
+ pub trait IntoUpdateValidatorFunc<Arg> {
900
+ /// Consume the closure/fn pointer and turn it into an update validator
901
+ fn into_update_validator_fn(self) -> BoxUpdateValidatorFn;
902
+ }
903
+ impl<A, F> IntoUpdateValidatorFunc<A> for F
904
+ where
905
+ A: FromJsonPayloadExt + Send,
906
+ F: (for<'a> Fn(&'a UpdateInfo, A) -> Result<(), anyhow::Error>) + Send + 'static,
907
+ {
908
+ fn into_update_validator_fn(self) -> BoxUpdateValidatorFn {
909
+ let wrapper = move |ctx: &UpdateInfo, input: &Payload| match A::from_json_payload(input) {
910
+ Ok(deser) => (self)(ctx, deser),
911
+ Err(e) => Err(e.into()),
912
+ };
913
+ Box::new(wrapper)
914
+ }
915
+ }
916
+ type BoxUpdateHandlerFn = Box<
917
+ dyn FnMut(UpdateContext, &Payload) -> BoxFuture<'static, Result<Payload, anyhow::Error>> + Send,
918
+ >;
919
+ /// Closures / functions which can be turned into update handler functions implement this trait
920
+ pub trait IntoUpdateHandlerFunc<Arg, Res> {
921
+ /// Consume the closure/fn pointer and turn it into an update handler
922
+ fn into_update_handler_fn(self) -> BoxUpdateHandlerFn;
923
+ }
924
+ impl<A, F, Rf, R> IntoUpdateHandlerFunc<A, R> for F
925
+ where
926
+ A: FromJsonPayloadExt + Send,
927
+ F: (FnMut(UpdateContext, A) -> Rf) + Send + 'static,
928
+ Rf: Future<Output = Result<R, anyhow::Error>> + Send + 'static,
929
+ R: AsJsonPayloadExt,
930
+ {
931
+ fn into_update_handler_fn(mut self) -> BoxUpdateHandlerFn {
932
+ let wrapper = move |ctx: UpdateContext, input: &Payload| match A::from_json_payload(input) {
933
+ Ok(deser) => (self)(ctx, deser)
934
+ .map(|r| r.and_then(|r| r.as_json_payload()))
935
+ .boxed(),
936
+ Err(e) => async move { Err(e.into()) }.boxed(),
937
+ };
938
+ Box::new(wrapper)
939
+ }
940
+ }
941
+
864
942
  /// Attempts to turn caught panics into something printable
865
943
  fn panic_formatter(panic: Box<dyn Any>) -> Box<dyn Display> {
866
944
  _panic_formatter::<&str>(panic)
@@ -107,6 +107,7 @@ pub struct LocalActivityOptions {
107
107
  /// Type of activity to schedule
108
108
  pub activity_type: String,
109
109
  /// Input to the activity
110
+ // TODO: Make optional
110
111
  pub input: Payload,
111
112
  /// Retry policy
112
113
  pub retry_policy: RetryPolicy,
@@ -177,6 +178,8 @@ pub struct ChildWorkflowOptions {
177
178
  pub workflow_id: String,
178
179
  /// Type of workflow to schedule
179
180
  pub workflow_type: String,
181
+ /// Task queue to schedule the workflow in
182
+ pub task_queue: String,
180
183
  /// Input to send the child Workflow
181
184
  pub input: Vec<Payload>,
182
185
  /// Cancellation strategy for the child workflow
@@ -194,6 +197,7 @@ impl IntoWorkflowCommand for ChildWorkflowOptions {
194
197
  seq,
195
198
  workflow_id: self.workflow_id,
196
199
  workflow_type: self.workflow_type,
200
+ task_queue: self.task_queue,
197
201
  input: self.input,
198
202
  cancellation_type: self.cancel_type as i32,
199
203
  workflow_id_reuse_policy: self.options.id_reuse_policy as i32,
@@ -7,8 +7,9 @@ pub use options::{
7
7
 
8
8
  use crate::{
9
9
  workflow_context::options::IntoWorkflowCommand, CancelExternalWfResult, CancellableID,
10
- CommandCreateRequest, CommandSubscribeChildWorkflowCompletion, RustWfCmd,
11
- SignalExternalWfResult, TimerResult, UnblockEvent, Unblockable,
10
+ CommandCreateRequest, CommandSubscribeChildWorkflowCompletion, IntoUpdateHandlerFunc,
11
+ IntoUpdateValidatorFunc, RustWfCmd, SignalExternalWfResult, TimerResult, UnblockEvent,
12
+ Unblockable, UpdateFunctions,
12
13
  };
13
14
  use crossbeam::channel::{Receiver, Sender};
14
15
  use futures::{task::Context, FutureExt, Stream, StreamExt};
@@ -45,16 +46,17 @@ use tokio::sync::{mpsc, oneshot, watch};
45
46
  use tokio_stream::wrappers::UnboundedReceiverStream;
46
47
 
47
48
  /// Used within workflows to issue commands, get info, etc.
49
+ #[derive(Clone)]
48
50
  pub struct WfContext {
49
51
  namespace: String,
50
52
  task_queue: String,
51
- args: Vec<Payload>,
53
+ args: Arc<Vec<Payload>>,
52
54
 
53
55
  chan: Sender<RustWfCmd>,
54
56
  am_cancelled: watch::Receiver<bool>,
55
- shared: Arc<RwLock<WfContextSharedData>>,
57
+ pub(crate) shared: Arc<RwLock<WfContextSharedData>>,
56
58
 
57
- seq_nums: RwLock<WfCtxProtectedDat>,
59
+ seq_nums: Arc<RwLock<WfCtxProtectedDat>>,
58
60
  }
59
61
 
60
62
  struct WfCtxProtectedDat {
@@ -94,12 +96,13 @@ impl WfCtxProtectedDat {
94
96
  }
95
97
 
96
98
  #[derive(Clone, Debug, Default)]
97
- pub struct WfContextSharedData {
99
+ pub(crate) struct WfContextSharedData {
98
100
  /// Maps change ids -> resolved status
99
101
  pub changes: HashMap<String, bool>,
100
102
  pub is_replaying: bool,
101
103
  pub wf_time: Option<SystemTime>,
102
104
  pub history_length: u32,
105
+ pub current_build_id: Option<String>,
103
106
  }
104
107
 
105
108
  // TODO: Dataconverter type interface to replace Payloads here. Possibly just use serde
@@ -119,17 +122,17 @@ impl WfContext {
119
122
  Self {
120
123
  namespace,
121
124
  task_queue,
122
- args,
125
+ args: Arc::new(args),
123
126
  chan,
124
127
  am_cancelled,
125
128
  shared: Arc::new(RwLock::new(Default::default())),
126
- seq_nums: RwLock::new(WfCtxProtectedDat {
129
+ seq_nums: Arc::new(RwLock::new(WfCtxProtectedDat {
127
130
  next_timer_sequence_number: 1,
128
131
  next_activity_sequence_number: 1,
129
132
  next_child_workflow_sequence_number: 1,
130
133
  next_cancel_external_wf_sequence_number: 1,
131
134
  next_signal_external_wf_sequence_number: 1,
132
- }),
135
+ })),
133
136
  },
134
137
  rx,
135
138
  )
@@ -155,16 +158,19 @@ impl WfContext {
155
158
  self.shared.read().history_length
156
159
  }
157
160
 
158
- pub(crate) fn get_shared_data(&self) -> Arc<RwLock<WfContextSharedData>> {
159
- self.shared.clone()
161
+ /// Return the Build ID as it was when this point in the workflow was first reached. If this
162
+ /// code is being executed for the first time, return this Worker's Build ID if it has one.
163
+ pub fn current_build_id(&self) -> Option<String> {
164
+ self.shared.read().current_build_id.clone()
160
165
  }
161
166
 
162
167
  /// A future that resolves if/when the workflow is cancelled
163
- pub async fn cancelled(&mut self) {
168
+ pub async fn cancelled(&self) {
164
169
  if *self.am_cancelled.borrow() {
165
170
  return;
166
171
  }
167
172
  self.am_cancelled
173
+ .clone()
168
174
  .changed()
169
175
  .await
170
176
  .expect("Cancelled send half not dropped");
@@ -298,7 +304,7 @@ impl WfContext {
298
304
  self.send(RustWfCmd::NewNonblockingCmd(
299
305
  workflow_command::Variant::UpsertWorkflowSearchAttributes(
300
306
  UpsertWorkflowSearchAttributes {
301
- search_attributes: HashMap::from_iter(attr_iter.into_iter()),
307
+ search_attributes: HashMap::from_iter(attr_iter),
302
308
  },
303
309
  ),
304
310
  ))
@@ -309,7 +315,7 @@ impl WfContext {
309
315
  self.send(RustWfCmd::NewNonblockingCmd(
310
316
  workflow_command::Variant::ModifyWorkflowProperties(ModifyWorkflowProperties {
311
317
  upserted_memo: Some(Memo {
312
- fields: HashMap::from_iter(attr_iter.into_iter()),
318
+ fields: HashMap::from_iter(attr_iter),
313
319
  }),
314
320
  }),
315
321
  ))
@@ -350,6 +356,24 @@ impl WfContext {
350
356
  cmd
351
357
  }
352
358
 
359
+ /// Register an update handler by providing the handler name, a validator function, and an
360
+ /// update handler. The validator must not mutate workflow state and is synchronous. The handler
361
+ /// may mutate workflow state (though, that's annoying right now in the prototype) and is async.
362
+ ///
363
+ /// Note that if you want a validator that always passes, you will likely need to provide type
364
+ /// annotations to make the compiler happy, like: `|_: &_, _: T| Ok(())`
365
+ pub fn update_handler<Arg, Res>(
366
+ &self,
367
+ name: impl Into<String>,
368
+ validator: impl IntoUpdateValidatorFunc<Arg>,
369
+ handler: impl IntoUpdateHandlerFunc<Arg, Res>,
370
+ ) {
371
+ self.send(RustWfCmd::RegisterUpdate(
372
+ name.into(),
373
+ UpdateFunctions::new(validator, handler),
374
+ ))
375
+ }
376
+
353
377
  fn send_signal_wf(
354
378
  &self,
355
379
  target: sig_we::Target,
@@ -612,9 +636,11 @@ pub struct ChildWfCommon {
612
636
  result_future: CancellableWFCommandFut<ChildWorkflowResult, ()>,
613
637
  }
614
638
 
639
+ /// Child workflow in pending state
615
640
  pub struct PendingChildWorkflow {
641
+ /// The status of the child workflow start
616
642
  pub status: ChildWorkflowStartStatus,
617
- pub common: ChildWfCommon,
643
+ pub(crate) common: ChildWfCommon,
618
644
  }
619
645
 
620
646
  impl PendingChildWorkflow {
@@ -631,7 +657,9 @@ impl PendingChildWorkflow {
631
657
  }
632
658
  }
633
659
 
660
+ /// Child workflow in started state
634
661
  pub struct StartedChildWorkflow {
662
+ /// Run ID of the child workflow
635
663
  pub run_id: String,
636
664
  common: ChildWfCommon,
637
665
  }