@temporalio/core-bridge 0.16.4 → 0.18.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.
- package/Cargo.lock +339 -226
- package/Cargo.toml +7 -3
- package/common.js +50 -0
- package/index.d.ts +7 -0
- package/index.js +12 -0
- package/package.json +7 -4
- package/releases/aarch64-apple-darwin/index.node +0 -0
- package/releases/aarch64-unknown-linux-gnu/index.node +0 -0
- package/{index.node → releases/index.node} +0 -0
- package/releases/x86_64-apple-darwin/index.node +0 -0
- package/releases/x86_64-pc-windows-msvc/index.node +0 -0
- package/releases/x86_64-unknown-linux-gnu/index.node +0 -0
- package/scripts/build.js +10 -50
- package/sdk-core/.buildkite/docker/Dockerfile +1 -1
- package/sdk-core/.buildkite/docker/docker-compose.yaml +2 -2
- package/sdk-core/.buildkite/pipeline.yml +2 -0
- package/sdk-core/Cargo.toml +1 -88
- package/sdk-core/README.md +30 -6
- package/sdk-core/bridge-ffi/Cargo.toml +24 -0
- package/sdk-core/bridge-ffi/LICENSE.txt +23 -0
- package/sdk-core/bridge-ffi/build.rs +25 -0
- package/sdk-core/bridge-ffi/include/sdk-core-bridge.h +216 -0
- package/sdk-core/bridge-ffi/src/lib.rs +829 -0
- package/sdk-core/bridge-ffi/src/wrappers.rs +193 -0
- package/sdk-core/client/Cargo.toml +32 -0
- package/sdk-core/{src/pollers/gateway.rs → client/src/lib.rs} +101 -195
- package/sdk-core/client/src/metrics.rs +89 -0
- package/sdk-core/client/src/mocks.rs +167 -0
- package/sdk-core/{src/pollers → client/src}/retry.rs +172 -14
- package/sdk-core/core/Cargo.toml +96 -0
- package/sdk-core/{src → core/src}/core_tests/activity_tasks.rs +193 -37
- package/sdk-core/{src → core/src}/core_tests/child_workflows.rs +14 -14
- package/sdk-core/{src → core/src}/core_tests/determinism.rs +8 -8
- package/sdk-core/core/src/core_tests/local_activities.rs +328 -0
- package/sdk-core/{src → core/src}/core_tests/mod.rs +6 -9
- package/sdk-core/{src → core/src}/core_tests/queries.rs +54 -54
- package/sdk-core/{src → core/src}/core_tests/replay_flag.rs +8 -12
- package/sdk-core/{src → core/src}/core_tests/workers.rs +120 -33
- package/sdk-core/{src → core/src}/core_tests/workflow_cancels.rs +16 -26
- package/sdk-core/{src → core/src}/core_tests/workflow_tasks.rs +280 -292
- package/sdk-core/core/src/lib.rs +374 -0
- package/sdk-core/{src → core/src}/log_export.rs +3 -27
- package/sdk-core/core/src/pending_activations.rs +162 -0
- package/sdk-core/{src → core/src}/pollers/mod.rs +4 -22
- package/sdk-core/{src → core/src}/pollers/poll_buffer.rs +1 -1
- package/sdk-core/core/src/protosext/mod.rs +396 -0
- package/sdk-core/core/src/replay/mod.rs +210 -0
- package/sdk-core/core/src/retry_logic.rs +144 -0
- package/sdk-core/{src → core/src}/telemetry/metrics.rs +3 -58
- package/sdk-core/{src → core/src}/telemetry/mod.rs +8 -8
- package/sdk-core/{src → core/src}/telemetry/prometheus_server.rs +0 -0
- package/sdk-core/{src → core/src}/test_help/mod.rs +35 -83
- package/sdk-core/{src → core/src}/worker/activities/activity_heartbeat_manager.rs +95 -42
- package/sdk-core/core/src/worker/activities/local_activities.rs +973 -0
- package/sdk-core/{src → core/src}/worker/activities.rs +52 -33
- package/sdk-core/{src → core/src}/worker/dispatcher.rs +8 -6
- package/sdk-core/{src → core/src}/worker/mod.rs +347 -221
- package/sdk-core/core/src/worker/wft_delivery.rs +81 -0
- package/sdk-core/{src → core/src}/workflow/bridge.rs +5 -2
- package/sdk-core/{src → core/src}/workflow/driven_workflow.rs +17 -7
- package/sdk-core/{src → core/src}/workflow/history_update.rs +33 -7
- package/sdk-core/{src → core/src/workflow}/machines/activity_state_machine.rs +26 -26
- package/sdk-core/{src → core/src/workflow}/machines/cancel_external_state_machine.rs +8 -11
- package/sdk-core/{src → core/src/workflow}/machines/cancel_workflow_state_machine.rs +19 -21
- package/sdk-core/{src → core/src/workflow}/machines/child_workflow_state_machine.rs +20 -31
- package/sdk-core/{src → core/src/workflow}/machines/complete_workflow_state_machine.rs +3 -5
- package/sdk-core/{src → core/src/workflow}/machines/continue_as_new_workflow_state_machine.rs +18 -18
- package/sdk-core/{src → core/src/workflow}/machines/fail_workflow_state_machine.rs +5 -6
- package/sdk-core/core/src/workflow/machines/local_activity_state_machine.rs +1451 -0
- package/sdk-core/{src → core/src/workflow}/machines/mod.rs +54 -107
- package/sdk-core/{src → core/src/workflow}/machines/mutable_side_effect_state_machine.rs +0 -0
- package/sdk-core/{src → core/src/workflow}/machines/patch_state_machine.rs +29 -30
- package/sdk-core/{src → core/src/workflow}/machines/side_effect_state_machine.rs +0 -0
- package/sdk-core/{src → core/src/workflow}/machines/signal_external_state_machine.rs +17 -19
- package/sdk-core/{src → core/src/workflow}/machines/timer_state_machine.rs +20 -21
- package/sdk-core/{src → core/src/workflow}/machines/transition_coverage.rs +5 -2
- package/sdk-core/{src → core/src/workflow}/machines/upsert_search_attributes_state_machine.rs +0 -0
- package/sdk-core/core/src/workflow/machines/workflow_machines/local_acts.rs +96 -0
- package/sdk-core/{src → core/src/workflow}/machines/workflow_machines.rs +357 -171
- package/sdk-core/{src → core/src/workflow}/machines/workflow_task_state_machine.rs +1 -1
- package/sdk-core/{src → core/src}/workflow/mod.rs +200 -39
- package/sdk-core/{src → core/src}/workflow/workflow_tasks/cache_manager.rs +0 -0
- package/sdk-core/{src → core/src}/workflow/workflow_tasks/concurrency_manager.rs +38 -5
- package/sdk-core/{src → core/src}/workflow/workflow_tasks/mod.rs +317 -103
- package/sdk-core/{test_utils → core-api}/Cargo.toml +10 -7
- package/sdk-core/{src → core-api/src}/errors.rs +42 -92
- package/sdk-core/core-api/src/lib.rs +158 -0
- package/sdk-core/{src/worker/config.rs → core-api/src/worker.rs} +18 -23
- package/sdk-core/etc/deps.svg +156 -0
- package/sdk-core/fsm/rustfsm_procmacro/src/lib.rs +5 -5
- package/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/no_handle_conversions_require_into_fail.stderr +3 -5
- package/sdk-core/fsm/rustfsm_trait/src/lib.rs +7 -1
- package/sdk-core/histories/fail_wf_task.bin +0 -0
- package/sdk-core/histories/timer_workflow_history.bin +0 -0
- package/sdk-core/protos/api_upstream/temporal/api/command/v1/message.proto +44 -13
- package/sdk-core/protos/api_upstream/temporal/api/common/v1/message.proto +19 -1
- package/sdk-core/protos/api_upstream/temporal/api/enums/v1/common.proto +1 -1
- package/sdk-core/protos/api_upstream/temporal/api/enums/v1/failed_cause.proto +9 -0
- package/sdk-core/protos/api_upstream/temporal/api/enums/v1/namespace.proto +1 -0
- package/sdk-core/protos/api_upstream/temporal/api/enums/v1/reset.proto +1 -0
- package/sdk-core/protos/api_upstream/temporal/api/enums/v1/task_queue.proto +13 -0
- package/sdk-core/protos/api_upstream/temporal/api/enums/v1/workflow.proto +14 -7
- package/sdk-core/protos/api_upstream/temporal/api/history/v1/message.proto +176 -18
- package/sdk-core/protos/api_upstream/temporal/api/namespace/v1/message.proto +6 -0
- package/sdk-core/protos/api_upstream/temporal/api/query/v1/message.proto +11 -0
- package/sdk-core/protos/api_upstream/temporal/api/taskqueue/v1/message.proto +3 -0
- package/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +156 -7
- package/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +135 -104
- package/sdk-core/protos/local/temporal/sdk/core/activity_result/activity_result.proto +78 -0
- package/sdk-core/protos/local/temporal/sdk/core/activity_task/activity_task.proto +78 -0
- package/sdk-core/protos/local/temporal/sdk/core/bridge/bridge.proto +205 -0
- package/sdk-core/protos/local/temporal/sdk/core/bridge/service.proto +61 -0
- package/sdk-core/protos/local/{child_workflow.proto → temporal/sdk/core/child_workflow/child_workflow.proto} +1 -1
- package/sdk-core/protos/local/{common.proto → temporal/sdk/core/common/common.proto} +5 -3
- package/sdk-core/protos/local/{core_interface.proto → temporal/sdk/core/core_interface.proto} +10 -10
- package/sdk-core/protos/local/temporal/sdk/core/external_data/external_data.proto +30 -0
- package/sdk-core/protos/local/{workflow_activation.proto → temporal/sdk/core/workflow_activation/workflow_activation.proto} +35 -11
- package/sdk-core/protos/local/{workflow_commands.proto → temporal/sdk/core/workflow_commands/workflow_commands.proto} +55 -4
- package/sdk-core/protos/local/{workflow_completion.proto → temporal/sdk/core/workflow_completion/workflow_completion.proto} +3 -3
- package/sdk-core/sdk/Cargo.toml +32 -0
- package/sdk-core/{src/prototype_rust_sdk → sdk/src}/conversions.rs +0 -0
- package/sdk-core/sdk/src/lib.rs +699 -0
- package/sdk-core/sdk/src/payload_converter.rs +11 -0
- package/sdk-core/sdk/src/workflow_context/options.rs +180 -0
- package/sdk-core/{src/prototype_rust_sdk → sdk/src}/workflow_context.rs +201 -124
- package/sdk-core/{src/prototype_rust_sdk → sdk/src}/workflow_future.rs +63 -30
- package/sdk-core/sdk-core-protos/Cargo.toml +10 -0
- package/sdk-core/sdk-core-protos/build.rs +28 -6
- package/sdk-core/sdk-core-protos/src/constants.rs +7 -0
- package/sdk-core/{src/test_help → sdk-core-protos/src}/history_builder.rs +134 -49
- package/sdk-core/sdk-core-protos/src/history_info.rs +216 -0
- package/sdk-core/sdk-core-protos/src/lib.rs +601 -168
- package/sdk-core/sdk-core-protos/src/task_token.rs +38 -0
- package/sdk-core/sdk-core-protos/src/utilities.rs +14 -0
- package/sdk-core/test-utils/Cargo.toml +32 -0
- package/sdk-core/{src/test_help → test-utils/src}/canned_histories.rs +59 -78
- package/sdk-core/test-utils/src/histfetch.rs +28 -0
- package/sdk-core/{test_utils → test-utils}/src/lib.rs +131 -68
- package/sdk-core/tests/integ_tests/client_tests.rs +1 -1
- package/sdk-core/tests/integ_tests/heartbeat_tests.rs +11 -7
- package/sdk-core/tests/integ_tests/polling_tests.rs +12 -11
- package/sdk-core/tests/integ_tests/queries_tests.rs +82 -78
- package/sdk-core/tests/integ_tests/workflow_tests/activities.rs +91 -71
- package/sdk-core/tests/integ_tests/workflow_tests/cancel_external.rs +3 -4
- package/sdk-core/tests/integ_tests/workflow_tests/cancel_wf.rs +2 -4
- package/sdk-core/tests/integ_tests/workflow_tests/child_workflows.rs +4 -6
- package/sdk-core/tests/integ_tests/workflow_tests/continue_as_new.rs +4 -6
- package/sdk-core/tests/integ_tests/workflow_tests/determinism.rs +3 -4
- package/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +496 -0
- package/sdk-core/tests/integ_tests/workflow_tests/patches.rs +5 -8
- package/sdk-core/tests/integ_tests/workflow_tests/replay.rs +125 -0
- package/sdk-core/tests/integ_tests/workflow_tests/signals.rs +7 -13
- package/sdk-core/tests/integ_tests/workflow_tests/stickyness.rs +33 -5
- package/sdk-core/tests/integ_tests/workflow_tests/timers.rs +12 -16
- package/sdk-core/tests/integ_tests/workflow_tests.rs +85 -82
- package/sdk-core/tests/load_tests.rs +6 -6
- package/sdk-core/tests/main.rs +2 -2
- package/src/conversions.rs +24 -21
- package/src/errors.rs +8 -0
- package/src/lib.rs +323 -211
- package/sdk-core/protos/local/activity_result.proto +0 -46
- package/sdk-core/protos/local/activity_task.proto +0 -66
- package/sdk-core/src/core_tests/retry.rs +0 -147
- package/sdk-core/src/lib.rs +0 -403
- package/sdk-core/src/machines/local_activity_state_machine.rs +0 -117
- package/sdk-core/src/pending_activations.rs +0 -249
- package/sdk-core/src/protosext/mod.rs +0 -160
- package/sdk-core/src/prototype_rust_sdk.rs +0 -412
- package/sdk-core/src/task_token.rs +0 -20
- package/sdk-core/src/test_help/history_info.rs +0 -157
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
mod workflow_machines;
|
|
2
2
|
|
|
3
|
-
// TODO: Move all these inside a submachines module
|
|
4
3
|
mod activity_state_machine;
|
|
5
4
|
mod cancel_external_state_machine;
|
|
6
5
|
mod cancel_workflow_state_machine;
|
|
@@ -8,7 +7,6 @@ mod child_workflow_state_machine;
|
|
|
8
7
|
mod complete_workflow_state_machine;
|
|
9
8
|
mod continue_as_new_workflow_state_machine;
|
|
10
9
|
mod fail_workflow_state_machine;
|
|
11
|
-
#[allow(unused)]
|
|
12
10
|
mod local_activity_state_machine;
|
|
13
11
|
#[allow(unused)]
|
|
14
12
|
mod mutable_side_effect_state_machine;
|
|
@@ -24,92 +22,35 @@ mod workflow_task_state_machine;
|
|
|
24
22
|
#[cfg(test)]
|
|
25
23
|
mod transition_coverage;
|
|
26
24
|
|
|
27
|
-
pub use patch_state_machine::HAS_CHANGE_MARKER_NAME;
|
|
28
25
|
pub(crate) use workflow_machines::{WFMachinesError, WorkflowMachines};
|
|
29
26
|
|
|
30
|
-
use crate::
|
|
27
|
+
use crate::telemetry::VecDisplayer;
|
|
28
|
+
use activity_state_machine::ActivityMachine;
|
|
29
|
+
use cancel_external_state_machine::CancelExternalMachine;
|
|
30
|
+
use cancel_workflow_state_machine::CancelWorkflowMachine;
|
|
31
|
+
use child_workflow_state_machine::ChildWorkflowMachine;
|
|
32
|
+
use complete_workflow_state_machine::CompleteWorkflowMachine;
|
|
33
|
+
use continue_as_new_workflow_state_machine::ContinueAsNewWorkflowMachine;
|
|
34
|
+
use fail_workflow_state_machine::FailWorkflowMachine;
|
|
35
|
+
use local_activity_state_machine::LocalActivityMachine;
|
|
36
|
+
use patch_state_machine::PatchMachine;
|
|
31
37
|
use prost::alloc::fmt::Formatter;
|
|
32
38
|
use rustfsm::{MachineError, StateMachine};
|
|
39
|
+
use signal_external_state_machine::SignalExternalMachine;
|
|
33
40
|
use std::{
|
|
34
41
|
convert::{TryFrom, TryInto},
|
|
35
42
|
fmt::{Debug, Display},
|
|
36
43
|
};
|
|
37
|
-
use temporal_sdk_core_protos::{
|
|
38
|
-
|
|
39
|
-
temporal::api::{command::v1::Command, enums::v1::CommandType, history::v1::HistoryEvent},
|
|
44
|
+
use temporal_sdk_core_protos::temporal::api::{
|
|
45
|
+
command::v1::Command as ProtoCommand, enums::v1::CommandType, history::v1::HistoryEvent,
|
|
40
46
|
};
|
|
47
|
+
use timer_state_machine::TimerMachine;
|
|
48
|
+
use workflow_machines::MachineResponse;
|
|
49
|
+
use workflow_task_state_machine::WorkflowTaskMachine;
|
|
41
50
|
|
|
42
51
|
#[cfg(test)]
|
|
43
52
|
use transition_coverage::add_coverage;
|
|
44
53
|
|
|
45
|
-
pub(crate) type ProtoCommand = Command;
|
|
46
|
-
|
|
47
|
-
/// [DrivenWorkflow]s respond with these when called, to indicate what they want to do next.
|
|
48
|
-
/// EX: Create a new timer, complete the workflow, etc.
|
|
49
|
-
#[derive(Debug, derive_more::From)]
|
|
50
|
-
#[allow(clippy::large_enum_variant)]
|
|
51
|
-
pub enum WFCommand {
|
|
52
|
-
/// Returned when we need to wait for the lang sdk to send us something
|
|
53
|
-
NoCommandsFromLang,
|
|
54
|
-
AddActivity(ScheduleActivity),
|
|
55
|
-
RequestCancelActivity(RequestCancelActivity),
|
|
56
|
-
AddTimer(StartTimer),
|
|
57
|
-
CancelTimer(CancelTimer),
|
|
58
|
-
CompleteWorkflow(CompleteWorkflowExecution),
|
|
59
|
-
FailWorkflow(FailWorkflowExecution),
|
|
60
|
-
QueryResponse(QueryResult),
|
|
61
|
-
ContinueAsNew(ContinueAsNewWorkflowExecution),
|
|
62
|
-
CancelWorkflow(CancelWorkflowExecution),
|
|
63
|
-
SetPatchMarker(SetPatchMarker),
|
|
64
|
-
AddChildWorkflow(StartChildWorkflowExecution),
|
|
65
|
-
CancelUnstartedChild(CancelUnstartedChildWorkflowExecution),
|
|
66
|
-
RequestCancelExternalWorkflow(RequestCancelExternalWorkflowExecution),
|
|
67
|
-
SignalExternalWorkflow(SignalExternalWorkflowExecution),
|
|
68
|
-
CancelSignalWorkflow(CancelSignalWorkflow),
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
#[derive(thiserror::Error, Debug, derive_more::From)]
|
|
72
|
-
#[error("Lang provided workflow command with empty variant")]
|
|
73
|
-
pub struct EmptyWorkflowCommandErr;
|
|
74
|
-
|
|
75
|
-
impl TryFrom<WorkflowCommand> for WFCommand {
|
|
76
|
-
type Error = EmptyWorkflowCommandErr;
|
|
77
|
-
|
|
78
|
-
fn try_from(c: WorkflowCommand) -> Result<Self, Self::Error> {
|
|
79
|
-
match c.variant.ok_or(EmptyWorkflowCommandErr)? {
|
|
80
|
-
workflow_command::Variant::StartTimer(s) => Ok(Self::AddTimer(s)),
|
|
81
|
-
workflow_command::Variant::CancelTimer(s) => Ok(Self::CancelTimer(s)),
|
|
82
|
-
workflow_command::Variant::ScheduleActivity(s) => Ok(Self::AddActivity(s)),
|
|
83
|
-
workflow_command::Variant::RequestCancelActivity(s) => {
|
|
84
|
-
Ok(Self::RequestCancelActivity(s))
|
|
85
|
-
}
|
|
86
|
-
workflow_command::Variant::CompleteWorkflowExecution(c) => {
|
|
87
|
-
Ok(Self::CompleteWorkflow(c))
|
|
88
|
-
}
|
|
89
|
-
workflow_command::Variant::FailWorkflowExecution(s) => Ok(Self::FailWorkflow(s)),
|
|
90
|
-
workflow_command::Variant::RespondToQuery(s) => Ok(Self::QueryResponse(s)),
|
|
91
|
-
workflow_command::Variant::ContinueAsNewWorkflowExecution(s) => {
|
|
92
|
-
Ok(Self::ContinueAsNew(s))
|
|
93
|
-
}
|
|
94
|
-
workflow_command::Variant::CancelWorkflowExecution(s) => Ok(Self::CancelWorkflow(s)),
|
|
95
|
-
workflow_command::Variant::SetPatchMarker(s) => Ok(Self::SetPatchMarker(s)),
|
|
96
|
-
workflow_command::Variant::StartChildWorkflowExecution(s) => {
|
|
97
|
-
Ok(Self::AddChildWorkflow(s))
|
|
98
|
-
}
|
|
99
|
-
workflow_command::Variant::RequestCancelExternalWorkflowExecution(s) => {
|
|
100
|
-
Ok(Self::RequestCancelExternalWorkflow(s))
|
|
101
|
-
}
|
|
102
|
-
workflow_command::Variant::SignalExternalWorkflowExecution(s) => {
|
|
103
|
-
Ok(Self::SignalExternalWorkflow(s))
|
|
104
|
-
}
|
|
105
|
-
workflow_command::Variant::CancelSignalWorkflow(s) => Ok(Self::CancelSignalWorkflow(s)),
|
|
106
|
-
workflow_command::Variant::CancelUnstartedChildWorkflowExecution(s) => {
|
|
107
|
-
Ok(Self::CancelUnstartedChild(s))
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
54
|
#[derive(Copy, Clone, Debug, derive_more::Display, Eq, PartialEq)]
|
|
114
55
|
enum MachineKind {
|
|
115
56
|
Activity,
|
|
@@ -119,16 +60,35 @@ enum MachineKind {
|
|
|
119
60
|
ContinueAsNewWorkflow,
|
|
120
61
|
FailWorkflow,
|
|
121
62
|
Timer,
|
|
122
|
-
|
|
63
|
+
Patch,
|
|
123
64
|
WorkflowTask,
|
|
124
65
|
SignalExternalWorkflow,
|
|
125
66
|
CancelExternalWorkflow,
|
|
67
|
+
LocalActivity,
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
#[enum_dispatch::enum_dispatch]
|
|
71
|
+
#[allow(clippy::enum_variant_names, clippy::large_enum_variant)]
|
|
72
|
+
enum Machines {
|
|
73
|
+
ActivityMachine,
|
|
74
|
+
CancelExternalMachine,
|
|
75
|
+
CancelWorkflowMachine,
|
|
76
|
+
ChildWorkflowMachine,
|
|
77
|
+
CompleteWorkflowMachine,
|
|
78
|
+
ContinueAsNewWorkflowMachine,
|
|
79
|
+
FailWorkflowMachine,
|
|
80
|
+
LocalActivityMachine,
|
|
81
|
+
PatchMachine,
|
|
82
|
+
SignalExternalMachine,
|
|
83
|
+
TimerMachine,
|
|
84
|
+
WorkflowTaskMachine,
|
|
126
85
|
}
|
|
127
86
|
|
|
128
87
|
/// Extends [rustfsm::StateMachine] with some functionality specific to the temporal SDK.
|
|
129
88
|
///
|
|
130
89
|
/// Formerly known as `EntityStateMachine` in Java.
|
|
131
|
-
|
|
90
|
+
#[enum_dispatch::enum_dispatch(Machines)]
|
|
91
|
+
trait TemporalStateMachine: Send {
|
|
132
92
|
fn kind(&self) -> MachineKind;
|
|
133
93
|
fn handle_command(
|
|
134
94
|
&mut self,
|
|
@@ -154,18 +114,14 @@ trait TemporalStateMachine: CheckStateMachineInFinal + Send {
|
|
|
154
114
|
/// Should return true if the command was cancelled before we sent it to the server. Always
|
|
155
115
|
/// returns false for non-cancellable machines
|
|
156
116
|
fn was_cancelled_before_sent_to_server(&self) -> bool;
|
|
117
|
+
|
|
118
|
+
/// Returns true if the state machine is in a final state
|
|
119
|
+
fn is_final_state(&self) -> bool;
|
|
157
120
|
}
|
|
158
121
|
|
|
159
122
|
impl<SM> TemporalStateMachine for SM
|
|
160
123
|
where
|
|
161
|
-
SM: StateMachine
|
|
162
|
-
+ CheckStateMachineInFinal
|
|
163
|
-
+ WFMachinesAdapter
|
|
164
|
-
+ Cancellable
|
|
165
|
-
+ OnEventWrapper
|
|
166
|
-
+ Clone
|
|
167
|
-
+ Send
|
|
168
|
-
+ 'static,
|
|
124
|
+
SM: StateMachine + WFMachinesAdapter + Cancellable + OnEventWrapper + Clone + Send + 'static,
|
|
169
125
|
<SM as StateMachine>::Event: TryFrom<HistoryEvent> + TryFrom<CommandType> + Display,
|
|
170
126
|
WFMachinesError: From<<<SM as StateMachine>::Event as TryFrom<HistoryEvent>>::Error>,
|
|
171
127
|
<SM as StateMachine>::Command: Debug + Display,
|
|
@@ -189,9 +145,13 @@ where
|
|
|
189
145
|
if let Ok(converted_command) = command_type.try_into() {
|
|
190
146
|
match OnEventWrapper::on_event_mut(self, converted_command) {
|
|
191
147
|
Ok(c) => process_machine_commands(self, c, None),
|
|
192
|
-
Err(MachineError::InvalidTransition) =>
|
|
193
|
-
format!(
|
|
194
|
-
|
|
148
|
+
Err(MachineError::InvalidTransition) => {
|
|
149
|
+
Err(WFMachinesError::Nondeterminism(format!(
|
|
150
|
+
"Unexpected command producing an invalid transition {:?} in state {}",
|
|
151
|
+
command_type,
|
|
152
|
+
self.state()
|
|
153
|
+
)))
|
|
154
|
+
}
|
|
195
155
|
Err(MachineError::Underlying(e)) => Err(e.into()),
|
|
196
156
|
}
|
|
197
157
|
} else {
|
|
@@ -253,6 +213,10 @@ where
|
|
|
253
213
|
fn was_cancelled_before_sent_to_server(&self) -> bool {
|
|
254
214
|
self.was_cancelled_before_sent_to_server()
|
|
255
215
|
}
|
|
216
|
+
|
|
217
|
+
fn is_final_state(&self) -> bool {
|
|
218
|
+
self.has_reached_final_state()
|
|
219
|
+
}
|
|
256
220
|
}
|
|
257
221
|
|
|
258
222
|
fn process_machine_commands<SM>(
|
|
@@ -277,22 +241,6 @@ where
|
|
|
277
241
|
Ok(machine_responses)
|
|
278
242
|
}
|
|
279
243
|
|
|
280
|
-
/// Exists purely to allow generic implementation of `is_final_state` for all [StateMachine]
|
|
281
|
-
/// implementors
|
|
282
|
-
trait CheckStateMachineInFinal {
|
|
283
|
-
/// Returns true if the state machine is in a final state
|
|
284
|
-
fn is_final_state(&self) -> bool;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
impl<SM> CheckStateMachineInFinal for SM
|
|
288
|
-
where
|
|
289
|
-
SM: StateMachine,
|
|
290
|
-
{
|
|
291
|
-
fn is_final_state(&self) -> bool {
|
|
292
|
-
self.on_final_state()
|
|
293
|
-
}
|
|
294
|
-
}
|
|
295
|
-
|
|
296
244
|
/// This trait exists to bridge [StateMachine]s and the [WorkflowMachines] instance. It has access
|
|
297
245
|
/// to the machine's concrete types while hiding those details from [WorkflowMachines]
|
|
298
246
|
trait WFMachinesAdapter: StateMachine {
|
|
@@ -378,10 +326,9 @@ where
|
|
|
378
326
|
{
|
|
379
327
|
}
|
|
380
328
|
|
|
381
|
-
|
|
382
|
-
struct NewMachineWithCommand<T: TemporalStateMachine> {
|
|
329
|
+
struct NewMachineWithCommand {
|
|
383
330
|
command: ProtoCommand,
|
|
384
|
-
machine:
|
|
331
|
+
machine: Machines,
|
|
385
332
|
}
|
|
386
333
|
|
|
387
334
|
impl Debug for dyn TemporalStateMachine {
|
|
File without changes
|
|
@@ -17,16 +17,15 @@
|
|
|
17
17
|
//! | deprecated marker for change | deprecate_patch | Call allowed |
|
|
18
18
|
//! | replaying, no marker | deprecate_patch | Call allowed |
|
|
19
19
|
|
|
20
|
-
use
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
NewMachineWithCommand, OnEventWrapper, WFMachinesAdapter, WFMachinesError,
|
|
24
|
-
},
|
|
25
|
-
protosext::HistoryEventExt,
|
|
20
|
+
use super::{
|
|
21
|
+
workflow_machines::MachineResponse, Cancellable, EventInfo, MachineKind, NewMachineWithCommand,
|
|
22
|
+
OnEventWrapper, WFMachinesAdapter, WFMachinesError,
|
|
26
23
|
};
|
|
24
|
+
use crate::protosext::HistoryEventExt;
|
|
27
25
|
use rustfsm::{fsm, TransitionResult};
|
|
28
26
|
use std::convert::TryFrom;
|
|
29
27
|
use temporal_sdk_core_protos::{
|
|
28
|
+
constants::PATCH_MARKER_NAME,
|
|
30
29
|
coresdk::common::build_has_change_marker_details,
|
|
31
30
|
temporal::api::{
|
|
32
31
|
command::v1::{Command, RecordMarkerCommandAttributes},
|
|
@@ -35,8 +34,6 @@ use temporal_sdk_core_protos::{
|
|
|
35
34
|
},
|
|
36
35
|
};
|
|
37
36
|
|
|
38
|
-
pub const HAS_CHANGE_MARKER_NAME: &str = "core_patch";
|
|
39
|
-
|
|
40
37
|
fsm! {
|
|
41
38
|
pub(super) name PatchMachine;
|
|
42
39
|
command PatchCommand;
|
|
@@ -78,10 +75,13 @@ pub(super) fn has_change(
|
|
|
78
75
|
patch_id: String,
|
|
79
76
|
replaying_when_invoked: bool,
|
|
80
77
|
deprecated: bool,
|
|
81
|
-
) -> NewMachineWithCommand
|
|
78
|
+
) -> NewMachineWithCommand {
|
|
82
79
|
let (machine, command) =
|
|
83
80
|
PatchMachine::new_scheduled(SharedState { patch_id }, replaying_when_invoked, deprecated);
|
|
84
|
-
NewMachineWithCommand {
|
|
81
|
+
NewMachineWithCommand {
|
|
82
|
+
command,
|
|
83
|
+
machine: machine.into(),
|
|
84
|
+
}
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
impl PatchMachine {
|
|
@@ -99,7 +99,7 @@ impl PatchMachine {
|
|
|
99
99
|
command_type: CommandType::RecordMarker as i32,
|
|
100
100
|
attributes: Some(
|
|
101
101
|
RecordMarkerCommandAttributes {
|
|
102
|
-
marker_name:
|
|
102
|
+
marker_name: PATCH_MARKER_NAME.to_string(),
|
|
103
103
|
details: build_has_change_marker_details(&state.patch_id, deprecated),
|
|
104
104
|
header: None,
|
|
105
105
|
failure: None,
|
|
@@ -184,11 +184,11 @@ impl WFMachinesAdapter for PatchMachine {
|
|
|
184
184
|
}
|
|
185
185
|
|
|
186
186
|
fn matches_event(&self, event: &HistoryEvent) -> bool {
|
|
187
|
-
event.
|
|
187
|
+
event.get_patch_marker_details().is_some()
|
|
188
188
|
}
|
|
189
189
|
|
|
190
190
|
fn kind(&self) -> MachineKind {
|
|
191
|
-
MachineKind::
|
|
191
|
+
MachineKind::Patch
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
194
|
|
|
@@ -209,7 +209,7 @@ impl TryFrom<HistoryEvent> for PatchMachineEvents {
|
|
|
209
209
|
type Error = WFMachinesError;
|
|
210
210
|
|
|
211
211
|
fn try_from(e: HistoryEvent) -> Result<Self, Self::Error> {
|
|
212
|
-
match e.
|
|
212
|
+
match e.get_patch_marker_details() {
|
|
213
213
|
Some((id, _)) => Ok(Self::MarkerRecorded(id)),
|
|
214
214
|
_ => Err(WFMachinesError::Nondeterminism(format!(
|
|
215
215
|
"Change machine cannot handle this event: {}",
|
|
@@ -222,17 +222,17 @@ impl TryFrom<HistoryEvent> for PatchMachineEvents {
|
|
|
222
222
|
#[cfg(test)]
|
|
223
223
|
mod tests {
|
|
224
224
|
use crate::{
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
test_help::TestHistoryBuilder,
|
|
228
|
-
workflow::managed_wf::ManagedWFFunc,
|
|
225
|
+
replay::TestHistoryBuilder,
|
|
226
|
+
workflow::{machines::WFMachinesError, managed_wf::ManagedWFFunc},
|
|
229
227
|
};
|
|
230
228
|
use rstest::rstest;
|
|
231
229
|
use std::time::Duration;
|
|
230
|
+
use temporal_sdk::{ActivityOptions, WfContext, WorkflowFunction};
|
|
232
231
|
use temporal_sdk_core_protos::{
|
|
232
|
+
constants::PATCH_MARKER_NAME,
|
|
233
233
|
coresdk::{
|
|
234
234
|
common::decode_change_marker_details,
|
|
235
|
-
workflow_activation::{
|
|
235
|
+
workflow_activation::{workflow_activation_job, NotifyHasPatch, WorkflowActivationJob},
|
|
236
236
|
},
|
|
237
237
|
temporal::api::{
|
|
238
238
|
command::v1::{
|
|
@@ -415,8 +415,7 @@ mod tests {
|
|
|
415
415
|
let mut wfm = patch_setup(replaying, marker_type, wf_version);
|
|
416
416
|
// Start workflow activation
|
|
417
417
|
wfm.get_next_activation().await.unwrap();
|
|
418
|
-
|
|
419
|
-
let commands = wfm.get_server_commands().await.commands;
|
|
418
|
+
let commands = wfm.get_server_commands().commands;
|
|
420
419
|
assert_eq!(commands.len(), 1);
|
|
421
420
|
assert_eq!(
|
|
422
421
|
commands[0].command_type,
|
|
@@ -440,8 +439,8 @@ mod tests {
|
|
|
440
439
|
// Activity is resolved
|
|
441
440
|
assert_matches!(
|
|
442
441
|
act.jobs.as_slice(),
|
|
443
|
-
[
|
|
444
|
-
variant: Some(
|
|
442
|
+
[WorkflowActivationJob {
|
|
443
|
+
variant: Some(workflow_activation_job::Variant::ResolveActivity(_))
|
|
445
444
|
}]
|
|
446
445
|
);
|
|
447
446
|
} else {
|
|
@@ -477,8 +476,8 @@ mod tests {
|
|
|
477
476
|
if replaying && marker_type != MarkerType::NoMarker {
|
|
478
477
|
assert_matches!(
|
|
479
478
|
&act.jobs[1],
|
|
480
|
-
|
|
481
|
-
variant: Some(
|
|
479
|
+
WorkflowActivationJob {
|
|
480
|
+
variant: Some(workflow_activation_job::Variant::NotifyHasPatch(
|
|
482
481
|
NotifyHasPatch {
|
|
483
482
|
patch_id,
|
|
484
483
|
}
|
|
@@ -488,7 +487,7 @@ mod tests {
|
|
|
488
487
|
} else {
|
|
489
488
|
assert_eq!(act.jobs.len(), 1);
|
|
490
489
|
}
|
|
491
|
-
let commands = wfm.get_server_commands().
|
|
490
|
+
let commands = wfm.get_server_commands().commands;
|
|
492
491
|
assert_eq!(commands.len(), 2);
|
|
493
492
|
let dep_flag_expected = wf_version != 2;
|
|
494
493
|
assert_matches!(
|
|
@@ -496,7 +495,7 @@ mod tests {
|
|
|
496
495
|
Attributes::RecordMarkerCommandAttributes(
|
|
497
496
|
RecordMarkerCommandAttributes { marker_name, details,.. })
|
|
498
497
|
|
|
499
|
-
if marker_name ==
|
|
498
|
+
if marker_name == PATCH_MARKER_NAME
|
|
500
499
|
&& decode_change_marker_details(details).unwrap().1 == dep_flag_expected
|
|
501
500
|
);
|
|
502
501
|
// The only time the "old" timer should fire is in v2, replaying, without a marker.
|
|
@@ -533,8 +532,8 @@ mod tests {
|
|
|
533
532
|
// Activity is resolved
|
|
534
533
|
assert_matches!(
|
|
535
534
|
act.jobs.as_slice(),
|
|
536
|
-
[
|
|
537
|
-
variant: Some(
|
|
535
|
+
[WorkflowActivationJob {
|
|
536
|
+
variant: Some(workflow_activation_job::Variant::ResolveActivity(_))
|
|
538
537
|
}]
|
|
539
538
|
);
|
|
540
539
|
|
|
@@ -550,7 +549,7 @@ mod tests {
|
|
|
550
549
|
// history that then suddenly doesn't have the marker.
|
|
551
550
|
#[tokio::test]
|
|
552
551
|
async fn same_change_multiple_spots(#[case] have_marker_in_hist: bool, #[case] replay: bool) {
|
|
553
|
-
let wfn = WorkflowFunction::new(move |
|
|
552
|
+
let wfn = WorkflowFunction::new(move |ctx: WfContext| async move {
|
|
554
553
|
if ctx.patched(MY_PATCH_ID) {
|
|
555
554
|
ctx.activity(ActivityOptions::default()).await;
|
|
556
555
|
} else {
|
|
File without changes
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
use
|
|
1
|
+
use super::{
|
|
2
2
|
workflow_machines::MachineResponse, Cancellable, EventInfo, MachineKind, NewMachineWithCommand,
|
|
3
3
|
OnEventWrapper, WFMachinesAdapter, WFMachinesError,
|
|
4
4
|
};
|
|
@@ -67,7 +67,7 @@ pub(super) fn new_external_signal(
|
|
|
67
67
|
signal_name: String,
|
|
68
68
|
payloads: impl IntoIterator<Item = Payload>,
|
|
69
69
|
only_child: bool,
|
|
70
|
-
) -> NewMachineWithCommand
|
|
70
|
+
) -> NewMachineWithCommand {
|
|
71
71
|
let mut s = SignalExternalMachine {
|
|
72
72
|
state: Created {}.into(),
|
|
73
73
|
shared_state: SharedState { seq },
|
|
@@ -81,9 +81,10 @@ pub(super) fn new_external_signal(
|
|
|
81
81
|
workflow_id: workflow_execution.workflow_id,
|
|
82
82
|
run_id: workflow_execution.run_id,
|
|
83
83
|
}),
|
|
84
|
+
header: None,
|
|
84
85
|
signal_name,
|
|
85
86
|
input: payloads.into_payloads(),
|
|
86
|
-
//
|
|
87
|
+
// Is deprecated
|
|
87
88
|
control: "".to_string(),
|
|
88
89
|
child_workflow_only: only_child,
|
|
89
90
|
},
|
|
@@ -94,7 +95,7 @@ pub(super) fn new_external_signal(
|
|
|
94
95
|
};
|
|
95
96
|
NewMachineWithCommand {
|
|
96
97
|
command: cmd,
|
|
97
|
-
machine: s,
|
|
98
|
+
machine: s.into(),
|
|
98
99
|
}
|
|
99
100
|
}
|
|
100
101
|
|
|
@@ -284,19 +285,16 @@ impl Cancellable for SignalExternalMachine {
|
|
|
284
285
|
#[cfg(test)]
|
|
285
286
|
mod tests {
|
|
286
287
|
use super::*;
|
|
287
|
-
use crate::{
|
|
288
|
-
prototype_rust_sdk::{CancellableFuture, WfContext, WorkflowFunction, WorkflowResult},
|
|
289
|
-
test_help::TestHistoryBuilder,
|
|
290
|
-
workflow::managed_wf::ManagedWFFunc,
|
|
291
|
-
};
|
|
288
|
+
use crate::{replay::TestHistoryBuilder, workflow::managed_wf::ManagedWFFunc};
|
|
292
289
|
use std::mem::discriminant;
|
|
290
|
+
use temporal_sdk::{CancellableFuture, WfContext, WorkflowFunction, WorkflowResult};
|
|
293
291
|
use temporal_sdk_core_protos::coresdk::workflow_activation::{
|
|
294
|
-
|
|
292
|
+
workflow_activation_job, WorkflowActivationJob,
|
|
295
293
|
};
|
|
296
294
|
|
|
297
295
|
const SIGNAME: &str = "signame";
|
|
298
296
|
|
|
299
|
-
async fn signal_sender(
|
|
297
|
+
async fn signal_sender(ctx: WfContext) -> WorkflowResult<()> {
|
|
300
298
|
let res = ctx
|
|
301
299
|
.signal_workflow("fake_wid", "fake_rid", SIGNAME, b"hi!")
|
|
302
300
|
.await;
|
|
@@ -327,14 +325,14 @@ mod tests {
|
|
|
327
325
|
let wff = WorkflowFunction::new(signal_sender);
|
|
328
326
|
let mut wfm = ManagedWFFunc::new(t, wff, vec![]);
|
|
329
327
|
wfm.get_next_activation().await.unwrap();
|
|
330
|
-
let cmds = wfm.get_server_commands().
|
|
328
|
+
let cmds = wfm.get_server_commands().commands;
|
|
331
329
|
assert_eq!(cmds.len(), 1);
|
|
332
330
|
assert_eq!(
|
|
333
331
|
cmds[0].command_type(),
|
|
334
332
|
CommandType::SignalExternalWorkflowExecution
|
|
335
333
|
);
|
|
336
334
|
wfm.get_next_activation().await.unwrap();
|
|
337
|
-
let cmds = wfm.get_server_commands().
|
|
335
|
+
let cmds = wfm.get_server_commands().commands;
|
|
338
336
|
assert_eq!(cmds.len(), 1);
|
|
339
337
|
if fails {
|
|
340
338
|
assert_eq!(cmds[0].command_type(), CommandType::FailWorkflowExecution);
|
|
@@ -355,9 +353,9 @@ mod tests {
|
|
|
355
353
|
t.add_full_wf_task();
|
|
356
354
|
t.add_workflow_execution_completed();
|
|
357
355
|
|
|
358
|
-
let wff = WorkflowFunction::new(|
|
|
356
|
+
let wff = WorkflowFunction::new(|ctx: WfContext| async move {
|
|
359
357
|
let sig = ctx.signal_workflow("fake_wid", "fake_rid", SIGNAME, b"hi!");
|
|
360
|
-
sig.cancel(&
|
|
358
|
+
sig.cancel(&ctx);
|
|
361
359
|
let _res = sig.await;
|
|
362
360
|
Ok(().into())
|
|
363
361
|
});
|
|
@@ -365,13 +363,13 @@ mod tests {
|
|
|
365
363
|
|
|
366
364
|
wfm.get_next_activation().await.unwrap();
|
|
367
365
|
// No commands b/c we're waiting on the signal which is immediately going to be cancelled
|
|
368
|
-
let cmds = wfm.get_server_commands().
|
|
366
|
+
let cmds = wfm.get_server_commands().commands;
|
|
369
367
|
assert_eq!(cmds.len(), 0);
|
|
370
368
|
let act = wfm.get_next_activation().await.unwrap();
|
|
371
369
|
assert_matches!(
|
|
372
370
|
&act.jobs[0],
|
|
373
|
-
|
|
374
|
-
variant: Some(
|
|
371
|
+
WorkflowActivationJob {
|
|
372
|
+
variant: Some(workflow_activation_job::Variant::ResolveSignalExternalWorkflow(
|
|
375
373
|
ResolveSignalExternalWorkflow {
|
|
376
374
|
failure: Some(c),
|
|
377
375
|
..
|
|
@@ -379,7 +377,7 @@ mod tests {
|
|
|
379
377
|
))
|
|
380
378
|
} => c.message == SIG_CANCEL_MSG
|
|
381
379
|
);
|
|
382
|
-
let cmds = wfm.get_server_commands().
|
|
380
|
+
let cmds = wfm.get_server_commands().commands;
|
|
383
381
|
assert_eq!(cmds.len(), 1);
|
|
384
382
|
assert_eq!(
|
|
385
383
|
cmds[0].command_type(),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#![allow(clippy::large_enum_variant)]
|
|
2
2
|
|
|
3
|
-
use
|
|
3
|
+
use super::{
|
|
4
4
|
workflow_machines::{MachineResponse, WFMachinesError},
|
|
5
5
|
Cancellable, EventInfo, MachineKind, NewMachineWithCommand, OnEventWrapper, WFMachinesAdapter,
|
|
6
6
|
};
|
|
@@ -61,11 +61,11 @@ pub(super) struct SharedState {
|
|
|
61
61
|
}
|
|
62
62
|
|
|
63
63
|
/// Creates a new, scheduled, timer as a [CancellableCommand]
|
|
64
|
-
pub(super) fn new_timer(attribs: StartTimer) -> NewMachineWithCommand
|
|
64
|
+
pub(super) fn new_timer(attribs: StartTimer) -> NewMachineWithCommand {
|
|
65
65
|
let (timer, add_cmd) = TimerMachine::new_scheduled(attribs);
|
|
66
66
|
NewMachineWithCommand {
|
|
67
67
|
command: add_cmd,
|
|
68
|
-
machine: timer,
|
|
68
|
+
machine: timer.into(),
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
|
|
@@ -274,13 +274,12 @@ impl Cancellable for TimerMachine {
|
|
|
274
274
|
mod test {
|
|
275
275
|
use super::*;
|
|
276
276
|
use crate::{
|
|
277
|
-
|
|
278
|
-
test_help::{canned_histories, TestHistoryBuilder},
|
|
277
|
+
replay::TestHistoryBuilder, test_help::canned_histories,
|
|
279
278
|
workflow::managed_wf::ManagedWFFunc,
|
|
280
279
|
};
|
|
281
280
|
use rstest::{fixture, rstest};
|
|
282
|
-
use std::mem::discriminant;
|
|
283
|
-
use
|
|
281
|
+
use std::{mem::discriminant, time::Duration};
|
|
282
|
+
use temporal_sdk::{CancellableFuture, WfContext, WorkflowFunction};
|
|
284
283
|
|
|
285
284
|
#[fixture]
|
|
286
285
|
fn happy_wfm() -> ManagedWFFunc {
|
|
@@ -295,7 +294,7 @@ mod test {
|
|
|
295
294
|
timer to fire. In the all-in-one-go test, the timer is created and resolved in the same
|
|
296
295
|
task, hence no extra loop.
|
|
297
296
|
*/
|
|
298
|
-
let func = WorkflowFunction::new(|
|
|
297
|
+
let func = WorkflowFunction::new(|command_sink: WfContext| async move {
|
|
299
298
|
command_sink.timer(Duration::from_secs(5)).await;
|
|
300
299
|
Ok(().into())
|
|
301
300
|
});
|
|
@@ -309,12 +308,12 @@ mod test {
|
|
|
309
308
|
#[tokio::test]
|
|
310
309
|
async fn test_fire_happy_path_inc(mut happy_wfm: ManagedWFFunc) {
|
|
311
310
|
happy_wfm.get_next_activation().await.unwrap();
|
|
312
|
-
let commands = happy_wfm.get_server_commands().
|
|
311
|
+
let commands = happy_wfm.get_server_commands().commands;
|
|
313
312
|
assert_eq!(commands.len(), 1);
|
|
314
313
|
assert_eq!(commands[0].command_type, CommandType::StartTimer as i32);
|
|
315
314
|
|
|
316
315
|
happy_wfm.get_next_activation().await.unwrap();
|
|
317
|
-
let commands = happy_wfm.get_server_commands().
|
|
316
|
+
let commands = happy_wfm.get_server_commands().commands;
|
|
318
317
|
assert_eq!(commands.len(), 1);
|
|
319
318
|
assert_eq!(commands.len(), 1);
|
|
320
319
|
assert_eq!(
|
|
@@ -328,7 +327,7 @@ mod test {
|
|
|
328
327
|
#[tokio::test]
|
|
329
328
|
async fn test_fire_happy_path_full(mut happy_wfm: ManagedWFFunc) {
|
|
330
329
|
happy_wfm.process_all_activations().await.unwrap();
|
|
331
|
-
let commands = happy_wfm.get_server_commands().
|
|
330
|
+
let commands = happy_wfm.get_server_commands().commands;
|
|
332
331
|
assert_eq!(commands.len(), 1);
|
|
333
332
|
assert_eq!(
|
|
334
333
|
commands[0].command_type,
|
|
@@ -339,7 +338,7 @@ mod test {
|
|
|
339
338
|
|
|
340
339
|
#[tokio::test(flavor = "multi_thread")]
|
|
341
340
|
async fn mismatched_timer_ids_errors() {
|
|
342
|
-
let func = WorkflowFunction::new(|
|
|
341
|
+
let func = WorkflowFunction::new(|command_sink: WfContext| async move {
|
|
343
342
|
command_sink.timer(Duration::from_secs(5)).await;
|
|
344
343
|
Ok(().into())
|
|
345
344
|
});
|
|
@@ -356,11 +355,11 @@ mod test {
|
|
|
356
355
|
|
|
357
356
|
#[fixture]
|
|
358
357
|
fn cancellation_setup() -> ManagedWFFunc {
|
|
359
|
-
let func = WorkflowFunction::new(|
|
|
358
|
+
let func = WorkflowFunction::new(|ctx: WfContext| async move {
|
|
360
359
|
let cancel_timer_fut = ctx.timer(Duration::from_secs(500));
|
|
361
360
|
ctx.timer(Duration::from_secs(5)).await;
|
|
362
361
|
// Cancel the first timer after having waited on the second
|
|
363
|
-
cancel_timer_fut.cancel(&
|
|
362
|
+
cancel_timer_fut.cancel(&ctx);
|
|
364
363
|
cancel_timer_fut.await;
|
|
365
364
|
Ok(().into())
|
|
366
365
|
});
|
|
@@ -373,13 +372,13 @@ mod test {
|
|
|
373
372
|
#[tokio::test]
|
|
374
373
|
async fn incremental_cancellation(#[from(cancellation_setup)] mut wfm: ManagedWFFunc) {
|
|
375
374
|
wfm.get_next_activation().await.unwrap();
|
|
376
|
-
let commands = wfm.get_server_commands().
|
|
375
|
+
let commands = wfm.get_server_commands().commands;
|
|
377
376
|
assert_eq!(commands.len(), 2);
|
|
378
377
|
assert_eq!(commands[0].command_type, CommandType::StartTimer as i32);
|
|
379
378
|
assert_eq!(commands[1].command_type, CommandType::StartTimer as i32);
|
|
380
379
|
|
|
381
380
|
wfm.get_next_activation().await.unwrap();
|
|
382
|
-
let commands = wfm.get_server_commands().
|
|
381
|
+
let commands = wfm.get_server_commands().commands;
|
|
383
382
|
assert_eq!(commands.len(), 2);
|
|
384
383
|
assert_eq!(commands[0].command_type, CommandType::CancelTimer as i32);
|
|
385
384
|
assert_eq!(
|
|
@@ -388,7 +387,7 @@ mod test {
|
|
|
388
387
|
);
|
|
389
388
|
|
|
390
389
|
assert!(wfm.get_next_activation().await.unwrap().jobs.is_empty());
|
|
391
|
-
let commands = wfm.get_server_commands().
|
|
390
|
+
let commands = wfm.get_server_commands().commands;
|
|
392
391
|
// There should be no commands - the wf completed at the same time the timer was cancelled
|
|
393
392
|
assert_eq!(commands.len(), 0);
|
|
394
393
|
wfm.shutdown().await.unwrap();
|
|
@@ -398,7 +397,7 @@ mod test {
|
|
|
398
397
|
#[tokio::test]
|
|
399
398
|
async fn full_cancellation(#[from(cancellation_setup)] mut wfm: ManagedWFFunc) {
|
|
400
399
|
wfm.process_all_activations().await.unwrap();
|
|
401
|
-
let commands = wfm.get_server_commands().
|
|
400
|
+
let commands = wfm.get_server_commands().commands;
|
|
402
401
|
// There should be no commands - the wf completed at the same time the timer was cancelled
|
|
403
402
|
assert_eq!(commands.len(), 0);
|
|
404
403
|
wfm.shutdown().await.unwrap();
|
|
@@ -406,10 +405,10 @@ mod test {
|
|
|
406
405
|
|
|
407
406
|
#[tokio::test(flavor = "multi_thread")]
|
|
408
407
|
async fn cancel_before_sent_to_server() {
|
|
409
|
-
let func = WorkflowFunction::new(|
|
|
408
|
+
let func = WorkflowFunction::new(|ctx: WfContext| async move {
|
|
410
409
|
let cancel_timer_fut = ctx.timer(Duration::from_secs(500));
|
|
411
410
|
// Immediately cancel the timer
|
|
412
|
-
cancel_timer_fut.cancel(&
|
|
411
|
+
cancel_timer_fut.cancel(&ctx);
|
|
413
412
|
cancel_timer_fut.await;
|
|
414
413
|
Ok(().into())
|
|
415
414
|
});
|
|
@@ -421,7 +420,7 @@ mod test {
|
|
|
421
420
|
let mut wfm = ManagedWFFunc::new(t, func, vec![]);
|
|
422
421
|
|
|
423
422
|
wfm.process_all_activations().await.unwrap();
|
|
424
|
-
let commands = wfm.get_server_commands().
|
|
423
|
+
let commands = wfm.get_server_commands().commands;
|
|
425
424
|
assert_eq!(commands.len(), 0);
|
|
426
425
|
wfm.shutdown().await.unwrap();
|
|
427
426
|
}
|