@temporalio/core-bridge 1.5.2 → 1.7.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 +304 -112
- package/lib/index.d.ts +8 -6
- package/lib/index.js.map +1 -1
- package/package.json +9 -4
- package/releases/aarch64-apple-darwin/index.node +0 -0
- package/releases/aarch64-unknown-linux-gnu/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/sdk-core/.buildkite/docker/Dockerfile +2 -2
- package/sdk-core/.buildkite/docker/docker-compose.yaml +1 -1
- package/sdk-core/.buildkite/pipeline.yml +2 -4
- package/sdk-core/.cargo/config.toml +5 -2
- package/sdk-core/.github/workflows/heavy.yml +29 -0
- package/sdk-core/Cargo.toml +1 -1
- package/sdk-core/README.md +20 -10
- package/sdk-core/client/src/lib.rs +215 -39
- package/sdk-core/client/src/metrics.rs +17 -8
- package/sdk-core/client/src/raw.rs +4 -4
- package/sdk-core/client/src/retry.rs +32 -20
- package/sdk-core/core/Cargo.toml +25 -12
- package/sdk-core/core/src/abstractions/take_cell.rs +28 -0
- package/sdk-core/core/src/abstractions.rs +204 -14
- package/sdk-core/core/src/core_tests/activity_tasks.rs +143 -50
- package/sdk-core/core/src/core_tests/child_workflows.rs +6 -5
- package/sdk-core/core/src/core_tests/determinism.rs +165 -2
- package/sdk-core/core/src/core_tests/local_activities.rs +431 -43
- package/sdk-core/core/src/core_tests/queries.rs +34 -16
- package/sdk-core/core/src/core_tests/workers.rs +8 -5
- package/sdk-core/core/src/core_tests/workflow_tasks.rs +588 -55
- package/sdk-core/core/src/ephemeral_server/mod.rs +113 -12
- package/sdk-core/core/src/internal_flags.rs +155 -0
- package/sdk-core/core/src/lib.rs +16 -9
- package/sdk-core/core/src/protosext/mod.rs +1 -1
- package/sdk-core/core/src/replay/mod.rs +16 -27
- package/sdk-core/core/src/telemetry/log_export.rs +1 -1
- package/sdk-core/core/src/telemetry/metrics.rs +69 -35
- package/sdk-core/core/src/telemetry/mod.rs +60 -21
- package/sdk-core/core/src/telemetry/prometheus_server.rs +19 -13
- package/sdk-core/core/src/test_help/mod.rs +73 -14
- package/sdk-core/core/src/worker/activities/activity_heartbeat_manager.rs +119 -160
- package/sdk-core/core/src/worker/activities/activity_task_poller_stream.rs +89 -0
- package/sdk-core/core/src/worker/activities/local_activities.rs +379 -129
- package/sdk-core/core/src/worker/activities.rs +350 -175
- package/sdk-core/core/src/worker/client/mocks.rs +22 -2
- package/sdk-core/core/src/worker/client.rs +18 -2
- package/sdk-core/core/src/worker/mod.rs +183 -64
- package/sdk-core/core/src/worker/workflow/bridge.rs +1 -3
- package/sdk-core/core/src/worker/workflow/driven_workflow.rs +3 -5
- package/sdk-core/core/src/worker/workflow/history_update.rs +916 -277
- package/sdk-core/core/src/worker/workflow/machines/activity_state_machine.rs +216 -183
- package/sdk-core/core/src/worker/workflow/machines/cancel_external_state_machine.rs +9 -12
- package/sdk-core/core/src/worker/workflow/machines/cancel_workflow_state_machine.rs +7 -9
- package/sdk-core/core/src/worker/workflow/machines/child_workflow_state_machine.rs +160 -87
- package/sdk-core/core/src/worker/workflow/machines/complete_workflow_state_machine.rs +13 -14
- package/sdk-core/core/src/worker/workflow/machines/continue_as_new_workflow_state_machine.rs +7 -9
- package/sdk-core/core/src/worker/workflow/machines/fail_workflow_state_machine.rs +14 -17
- package/sdk-core/core/src/worker/workflow/machines/local_activity_state_machine.rs +242 -110
- package/sdk-core/core/src/worker/workflow/machines/mod.rs +27 -19
- package/sdk-core/core/src/worker/workflow/machines/modify_workflow_properties_state_machine.rs +9 -11
- package/sdk-core/core/src/worker/workflow/machines/patch_state_machine.rs +321 -206
- package/sdk-core/core/src/worker/workflow/machines/signal_external_state_machine.rs +13 -18
- package/sdk-core/core/src/worker/workflow/machines/timer_state_machine.rs +20 -29
- package/sdk-core/core/src/worker/workflow/machines/transition_coverage.rs +2 -2
- package/sdk-core/core/src/worker/workflow/machines/upsert_search_attributes_state_machine.rs +257 -51
- package/sdk-core/core/src/worker/workflow/machines/workflow_machines/local_acts.rs +6 -17
- package/sdk-core/core/src/worker/workflow/machines/workflow_machines.rs +310 -150
- package/sdk-core/core/src/worker/workflow/machines/workflow_task_state_machine.rs +17 -20
- package/sdk-core/core/src/worker/workflow/managed_run/managed_wf_test.rs +31 -15
- package/sdk-core/core/src/worker/workflow/managed_run.rs +1052 -380
- package/sdk-core/core/src/worker/workflow/mod.rs +598 -390
- package/sdk-core/core/src/worker/workflow/run_cache.rs +40 -57
- package/sdk-core/core/src/worker/workflow/wft_extraction.rs +137 -0
- package/sdk-core/core/src/worker/workflow/wft_poller.rs +1 -4
- package/sdk-core/core/src/worker/workflow/workflow_stream/saved_wf_inputs.rs +117 -0
- package/sdk-core/core/src/worker/workflow/workflow_stream/tonic_status_serde.rs +24 -0
- package/sdk-core/core/src/worker/workflow/workflow_stream.rs +469 -718
- package/sdk-core/core-api/Cargo.toml +2 -1
- package/sdk-core/core-api/src/errors.rs +1 -34
- package/sdk-core/core-api/src/lib.rs +19 -9
- package/sdk-core/core-api/src/telemetry.rs +4 -6
- package/sdk-core/core-api/src/worker.rs +19 -1
- package/sdk-core/etc/deps.svg +115 -140
- package/sdk-core/etc/regen-depgraph.sh +5 -0
- package/sdk-core/fsm/rustfsm_procmacro/src/lib.rs +86 -61
- package/sdk-core/fsm/rustfsm_trait/src/lib.rs +29 -71
- package/sdk-core/histories/ends_empty_wft_complete.bin +0 -0
- package/sdk-core/histories/evict_while_la_running_no_interference-16_history.bin +0 -0
- package/sdk-core/histories/old_change_marker_format.bin +0 -0
- package/sdk-core/protos/api_upstream/.github/CODEOWNERS +2 -1
- package/sdk-core/protos/api_upstream/Makefile +6 -6
- package/sdk-core/protos/api_upstream/build/go.mod +7 -0
- package/sdk-core/protos/api_upstream/build/go.sum +5 -0
- package/sdk-core/protos/api_upstream/build/tools.go +29 -0
- package/sdk-core/protos/api_upstream/go.mod +6 -0
- package/sdk-core/protos/api_upstream/temporal/api/batch/v1/message.proto +9 -2
- package/sdk-core/protos/api_upstream/temporal/api/command/v1/message.proto +7 -26
- package/sdk-core/protos/api_upstream/temporal/api/common/v1/message.proto +13 -2
- package/sdk-core/protos/api_upstream/temporal/api/enums/v1/batch_operation.proto +3 -2
- package/sdk-core/protos/api_upstream/temporal/api/enums/v1/command_type.proto +3 -7
- package/sdk-core/protos/api_upstream/temporal/api/enums/v1/common.proto +3 -2
- package/sdk-core/protos/api_upstream/temporal/api/enums/v1/event_type.proto +8 -8
- package/sdk-core/protos/api_upstream/temporal/api/enums/v1/failed_cause.proto +25 -2
- package/sdk-core/protos/api_upstream/temporal/api/enums/v1/namespace.proto +2 -2
- package/sdk-core/protos/api_upstream/temporal/api/enums/v1/query.proto +2 -2
- package/sdk-core/protos/api_upstream/temporal/api/enums/v1/reset.proto +2 -2
- package/sdk-core/protos/api_upstream/temporal/api/enums/v1/schedule.proto +2 -2
- package/sdk-core/protos/api_upstream/temporal/api/enums/v1/task_queue.proto +2 -2
- package/sdk-core/protos/api_upstream/temporal/api/enums/v1/update.proto +24 -19
- package/sdk-core/protos/api_upstream/temporal/api/enums/v1/workflow.proto +2 -2
- package/sdk-core/protos/api_upstream/temporal/api/errordetails/v1/message.proto +2 -2
- package/sdk-core/protos/api_upstream/temporal/api/failure/v1/message.proto +2 -2
- package/sdk-core/protos/api_upstream/temporal/api/filter/v1/message.proto +2 -2
- package/sdk-core/protos/api_upstream/temporal/api/history/v1/message.proto +49 -26
- package/sdk-core/protos/api_upstream/temporal/api/namespace/v1/message.proto +4 -2
- package/sdk-core/protos/api_upstream/temporal/api/operatorservice/v1/request_response.proto +5 -2
- package/sdk-core/protos/api_upstream/temporal/api/operatorservice/v1/service.proto +2 -2
- package/sdk-core/protos/api_upstream/temporal/api/protocol/v1/message.proto +57 -0
- package/sdk-core/protos/api_upstream/temporal/api/query/v1/message.proto +2 -2
- package/sdk-core/protos/api_upstream/temporal/api/replication/v1/message.proto +2 -2
- package/sdk-core/protos/api_upstream/temporal/api/schedule/v1/message.proto +2 -2
- package/sdk-core/protos/api_upstream/temporal/api/sdk/v1/task_complete_metadata.proto +63 -0
- package/sdk-core/protos/api_upstream/temporal/api/taskqueue/v1/message.proto +2 -2
- package/sdk-core/protos/api_upstream/temporal/api/update/v1/message.proto +71 -6
- package/sdk-core/protos/api_upstream/temporal/api/version/v1/message.proto +2 -2
- package/sdk-core/protos/api_upstream/temporal/api/workflow/v1/message.proto +2 -2
- package/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +64 -28
- package/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +4 -4
- package/sdk-core/protos/local/temporal/sdk/core/activity_result/activity_result.proto +7 -8
- package/sdk-core/protos/local/temporal/sdk/core/activity_task/activity_task.proto +10 -7
- package/sdk-core/protos/local/temporal/sdk/core/child_workflow/child_workflow.proto +19 -30
- package/sdk-core/protos/local/temporal/sdk/core/common/common.proto +1 -0
- package/sdk-core/protos/local/temporal/sdk/core/core_interface.proto +1 -0
- package/sdk-core/protos/local/temporal/sdk/core/external_data/external_data.proto +8 -0
- package/sdk-core/protos/local/temporal/sdk/core/workflow_activation/workflow_activation.proto +67 -60
- package/sdk-core/protos/local/temporal/sdk/core/workflow_commands/workflow_commands.proto +85 -84
- package/sdk-core/protos/local/temporal/sdk/core/workflow_completion/workflow_completion.proto +9 -3
- package/sdk-core/protos/testsrv_upstream/temporal/api/testservice/v1/request_response.proto +2 -2
- package/sdk-core/protos/testsrv_upstream/temporal/api/testservice/v1/service.proto +2 -2
- package/sdk-core/sdk/Cargo.toml +5 -4
- package/sdk-core/sdk/src/lib.rs +108 -26
- package/sdk-core/sdk/src/workflow_context/options.rs +7 -1
- package/sdk-core/sdk/src/workflow_context.rs +24 -17
- package/sdk-core/sdk/src/workflow_future.rs +16 -15
- package/sdk-core/sdk-core-protos/Cargo.toml +5 -2
- package/sdk-core/sdk-core-protos/build.rs +36 -2
- package/sdk-core/sdk-core-protos/src/history_builder.rs +138 -106
- package/sdk-core/sdk-core-protos/src/history_info.rs +10 -1
- package/sdk-core/sdk-core-protos/src/lib.rs +272 -87
- package/sdk-core/sdk-core-protos/src/task_token.rs +12 -2
- package/sdk-core/test-utils/Cargo.toml +3 -1
- package/sdk-core/test-utils/src/canned_histories.rs +106 -296
- package/sdk-core/test-utils/src/histfetch.rs +1 -1
- package/sdk-core/test-utils/src/lib.rs +82 -23
- package/sdk-core/test-utils/src/wf_input_saver.rs +50 -0
- package/sdk-core/test-utils/src/workflows.rs +29 -0
- package/sdk-core/tests/fuzzy_workflow.rs +130 -0
- package/sdk-core/tests/{load_tests.rs → heavy_tests.rs} +125 -51
- package/sdk-core/tests/integ_tests/ephemeral_server_tests.rs +25 -3
- package/sdk-core/tests/integ_tests/heartbeat_tests.rs +10 -5
- package/sdk-core/tests/integ_tests/metrics_tests.rs +218 -16
- package/sdk-core/tests/integ_tests/polling_tests.rs +4 -47
- package/sdk-core/tests/integ_tests/queries_tests.rs +5 -128
- package/sdk-core/tests/integ_tests/visibility_tests.rs +83 -25
- package/sdk-core/tests/integ_tests/workflow_tests/activities.rs +161 -72
- package/sdk-core/tests/integ_tests/workflow_tests/cancel_external.rs +1 -0
- package/sdk-core/tests/integ_tests/workflow_tests/cancel_wf.rs +6 -13
- package/sdk-core/tests/integ_tests/workflow_tests/child_workflows.rs +80 -3
- package/sdk-core/tests/integ_tests/workflow_tests/continue_as_new.rs +6 -2
- package/sdk-core/tests/integ_tests/workflow_tests/determinism.rs +3 -10
- package/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +94 -200
- package/sdk-core/tests/integ_tests/workflow_tests/modify_wf_properties.rs +2 -4
- package/sdk-core/tests/integ_tests/workflow_tests/patches.rs +34 -28
- package/sdk-core/tests/integ_tests/workflow_tests/replay.rs +76 -7
- package/sdk-core/tests/integ_tests/workflow_tests/resets.rs +1 -0
- package/sdk-core/tests/integ_tests/workflow_tests/signals.rs +18 -14
- package/sdk-core/tests/integ_tests/workflow_tests/stickyness.rs +6 -20
- package/sdk-core/tests/integ_tests/workflow_tests/timers.rs +10 -21
- package/sdk-core/tests/integ_tests/workflow_tests/upsert_search_attrs.rs +7 -8
- package/sdk-core/tests/integ_tests/workflow_tests.rs +13 -14
- package/sdk-core/tests/main.rs +3 -13
- package/sdk-core/tests/runner.rs +75 -36
- package/sdk-core/tests/wf_input_replay.rs +32 -0
- package/src/conversions.rs +14 -8
- package/src/runtime.rs +9 -8
- package/ts/index.ts +8 -6
- package/sdk-core/bridge-ffi/Cargo.toml +0 -24
- package/sdk-core/bridge-ffi/LICENSE.txt +0 -23
- package/sdk-core/bridge-ffi/build.rs +0 -25
- package/sdk-core/bridge-ffi/include/sdk-core-bridge.h +0 -224
- package/sdk-core/bridge-ffi/src/lib.rs +0 -746
- package/sdk-core/bridge-ffi/src/wrappers.rs +0 -221
- package/sdk-core/protos/local/temporal/sdk/core/bridge/bridge.proto +0 -210
- package/sdk-core/sdk/src/conversions.rs +0 -8
|
@@ -2,7 +2,8 @@ use super::{
|
|
|
2
2
|
workflow_machines::MachineResponse, Cancellable, EventInfo, NewMachineWithCommand,
|
|
3
3
|
OnEventWrapper, WFMachinesAdapter, WFMachinesError,
|
|
4
4
|
};
|
|
5
|
-
use
|
|
5
|
+
use crate::worker::workflow::machines::HistEventData;
|
|
6
|
+
use rustfsm::{fsm, StateMachine, TransitionResult};
|
|
6
7
|
use std::convert::TryFrom;
|
|
7
8
|
use temporal_sdk_core_protos::{
|
|
8
9
|
coresdk::{
|
|
@@ -60,10 +61,7 @@ pub(super) fn new_external_cancel(
|
|
|
60
61
|
only_child: bool,
|
|
61
62
|
reason: String,
|
|
62
63
|
) -> NewMachineWithCommand {
|
|
63
|
-
let mut s = CancelExternalMachine {
|
|
64
|
-
state: Created {}.into(),
|
|
65
|
-
shared_state: SharedState { seq },
|
|
66
|
-
};
|
|
64
|
+
let mut s = CancelExternalMachine::from_parts(Created {}.into(), SharedState { seq });
|
|
67
65
|
OnEventWrapper::on_event_mut(&mut s, CancelExternalMachineEvents::Schedule)
|
|
68
66
|
.expect("Scheduling cancel external wf command doesn't fail");
|
|
69
67
|
let cmd_attrs = command::Attributes::RequestCancelExternalWorkflowExecutionCommandAttributes(
|
|
@@ -145,10 +143,11 @@ impl TryFrom<CommandType> for CancelExternalMachineEvents {
|
|
|
145
143
|
}
|
|
146
144
|
}
|
|
147
145
|
|
|
148
|
-
impl TryFrom<
|
|
146
|
+
impl TryFrom<HistEventData> for CancelExternalMachineEvents {
|
|
149
147
|
type Error = WFMachinesError;
|
|
150
148
|
|
|
151
|
-
fn try_from(e:
|
|
149
|
+
fn try_from(e: HistEventData) -> Result<Self, Self::Error> {
|
|
150
|
+
let e = e.event;
|
|
152
151
|
Ok(match e.event_type() {
|
|
153
152
|
EventType::ExternalWorkflowExecutionCancelRequested => {
|
|
154
153
|
Self::ExternalWorkflowExecutionCancelRequested
|
|
@@ -161,15 +160,13 @@ impl TryFrom<HistoryEvent> for CancelExternalMachineEvents {
|
|
|
161
160
|
Self::RequestCancelExternalWorkflowExecutionFailed(attrs.cause())
|
|
162
161
|
} else {
|
|
163
162
|
return Err(WFMachinesError::Fatal(format!(
|
|
164
|
-
"Cancelworkflow failed attributes were unset: {}"
|
|
165
|
-
e
|
|
163
|
+
"Cancelworkflow failed attributes were unset: {e}"
|
|
166
164
|
)));
|
|
167
165
|
}
|
|
168
166
|
}
|
|
169
167
|
_ => {
|
|
170
168
|
return Err(WFMachinesError::Nondeterminism(format!(
|
|
171
|
-
"Cancel external WF machine does not handle this event: {}"
|
|
172
|
-
e
|
|
169
|
+
"Cancel external WF machine does not handle this event: {e}"
|
|
173
170
|
)))
|
|
174
171
|
}
|
|
175
172
|
})
|
|
@@ -199,7 +196,7 @@ impl WFMachinesAdapter for CancelExternalMachine {
|
|
|
199
196
|
vec![ResolveRequestCancelExternalWorkflow {
|
|
200
197
|
seq: self.shared_state.seq,
|
|
201
198
|
failure: Some(Failure {
|
|
202
|
-
message: format!("Unable to cancel external workflow because {}"
|
|
199
|
+
message: format!("Unable to cancel external workflow because {reason}"),
|
|
203
200
|
failure_info: Some(FailureInfo::ApplicationFailureInfo(
|
|
204
201
|
ApplicationFailureInfo {
|
|
205
202
|
r#type: f.to_string(),
|
|
@@ -2,7 +2,8 @@ use super::{
|
|
|
2
2
|
workflow_machines::MachineResponse, Cancellable, EventInfo, HistoryEvent,
|
|
3
3
|
NewMachineWithCommand, OnEventWrapper, WFMachinesAdapter, WFMachinesError,
|
|
4
4
|
};
|
|
5
|
-
use
|
|
5
|
+
use crate::worker::workflow::machines::HistEventData;
|
|
6
|
+
use rustfsm::{fsm, StateMachine, TransitionResult};
|
|
6
7
|
use std::convert::TryFrom;
|
|
7
8
|
use temporal_sdk_core_protos::{
|
|
8
9
|
coresdk::workflow_commands::CancelWorkflowExecution,
|
|
@@ -33,10 +34,7 @@ pub(super) enum CancelWorkflowMachineError {}
|
|
|
33
34
|
pub(super) enum CancelWorkflowCommand {}
|
|
34
35
|
|
|
35
36
|
pub(super) fn cancel_workflow(attribs: CancelWorkflowExecution) -> NewMachineWithCommand {
|
|
36
|
-
let mut machine = CancelWorkflowMachine {
|
|
37
|
-
state: Created {}.into(),
|
|
38
|
-
shared_state: (),
|
|
39
|
-
};
|
|
37
|
+
let mut machine = CancelWorkflowMachine::from_parts(Created {}.into(), ());
|
|
40
38
|
OnEventWrapper::on_event_mut(&mut machine, CancelWorkflowMachineEvents::Schedule)
|
|
41
39
|
.expect("Scheduling continue as new machine doesn't fail");
|
|
42
40
|
let command = Command {
|
|
@@ -72,16 +70,16 @@ impl Created {
|
|
|
72
70
|
}
|
|
73
71
|
}
|
|
74
72
|
|
|
75
|
-
impl TryFrom<
|
|
73
|
+
impl TryFrom<HistEventData> for CancelWorkflowMachineEvents {
|
|
76
74
|
type Error = WFMachinesError;
|
|
77
75
|
|
|
78
|
-
fn try_from(e:
|
|
76
|
+
fn try_from(e: HistEventData) -> Result<Self, Self::Error> {
|
|
77
|
+
let e = e.event;
|
|
79
78
|
Ok(match EventType::from_i32(e.event_type) {
|
|
80
79
|
Some(EventType::WorkflowExecutionCanceled) => Self::WorkflowExecutionCanceled,
|
|
81
80
|
_ => {
|
|
82
81
|
return Err(WFMachinesError::Nondeterminism(format!(
|
|
83
|
-
"Cancel workflow machine does not handle this event: {}"
|
|
84
|
-
e
|
|
82
|
+
"Cancel workflow machine does not handle this event: {e}"
|
|
85
83
|
)))
|
|
86
84
|
}
|
|
87
85
|
})
|
|
@@ -2,7 +2,11 @@ use super::{
|
|
|
2
2
|
workflow_machines::MachineResponse, Cancellable, EventInfo, NewMachineWithCommand,
|
|
3
3
|
OnEventWrapper, WFMachinesAdapter, WFMachinesError,
|
|
4
4
|
};
|
|
5
|
-
use
|
|
5
|
+
use crate::{
|
|
6
|
+
internal_flags::CoreInternalFlags,
|
|
7
|
+
worker::workflow::{machines::HistEventData, InternalFlagsRef},
|
|
8
|
+
};
|
|
9
|
+
use rustfsm::{fsm, MachineError, StateMachine, TransitionResult};
|
|
6
10
|
use std::convert::{TryFrom, TryInto};
|
|
7
11
|
use temporal_sdk_core_protos::{
|
|
8
12
|
coresdk::{
|
|
@@ -41,7 +45,7 @@ fsm! {
|
|
|
41
45
|
|
|
42
46
|
Created --(Schedule, on_schedule) --> StartCommandCreated;
|
|
43
47
|
StartCommandCreated --(CommandStartChildWorkflowExecution) --> StartCommandCreated;
|
|
44
|
-
StartCommandCreated --(StartChildWorkflowExecutionInitiated(
|
|
48
|
+
StartCommandCreated --(StartChildWorkflowExecutionInitiated(ChildWorkflowInitiatedData),
|
|
45
49
|
shared on_start_child_workflow_execution_initiated) --> StartEventRecorded;
|
|
46
50
|
StartCommandCreated --(Cancel, shared on_cancelled) --> Cancelled;
|
|
47
51
|
|
|
@@ -70,6 +74,8 @@ fsm! {
|
|
|
70
74
|
|
|
71
75
|
// Ignore any spurious cancellations after resolution
|
|
72
76
|
Cancelled --(Cancel) --> Cancelled;
|
|
77
|
+
Cancelled --(ChildWorkflowExecutionCancelled,
|
|
78
|
+
on_child_workflow_execution_cancelled) --> Cancelled;
|
|
73
79
|
Failed --(Cancel) --> Failed;
|
|
74
80
|
StartFailed --(Cancel) --> StartFailed;
|
|
75
81
|
TimedOut --(Cancel) --> TimedOut;
|
|
@@ -99,8 +105,38 @@ pub(super) enum ChildWorkflowCommand {
|
|
|
99
105
|
IssueCancelAfterStarted { reason: String },
|
|
100
106
|
}
|
|
101
107
|
|
|
108
|
+
pub(super) struct ChildWorkflowInitiatedData {
|
|
109
|
+
event_id: i64,
|
|
110
|
+
wf_type: String,
|
|
111
|
+
wf_id: String,
|
|
112
|
+
last_task_in_history: bool,
|
|
113
|
+
}
|
|
114
|
+
|
|
102
115
|
#[derive(Default, Clone)]
|
|
103
|
-
pub(super) struct Cancelled {
|
|
116
|
+
pub(super) struct Cancelled {
|
|
117
|
+
seen_cancelled_event: bool,
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
impl Cancelled {
|
|
121
|
+
pub(super) fn on_child_workflow_execution_cancelled(
|
|
122
|
+
self,
|
|
123
|
+
) -> ChildWorkflowMachineTransition<Cancelled> {
|
|
124
|
+
if self.seen_cancelled_event {
|
|
125
|
+
ChildWorkflowMachineTransition::Err(WFMachinesError::Fatal(
|
|
126
|
+
"Child workflow has already seen a ChildWorkflowExecutionCanceledEvent, and now \
|
|
127
|
+
another is being applied! This is a bug, please report."
|
|
128
|
+
.to_string(),
|
|
129
|
+
))
|
|
130
|
+
} else {
|
|
131
|
+
ChildWorkflowMachineTransition::ok(
|
|
132
|
+
[],
|
|
133
|
+
Cancelled {
|
|
134
|
+
seen_cancelled_event: true,
|
|
135
|
+
},
|
|
136
|
+
)
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
104
140
|
|
|
105
141
|
#[derive(Default, Clone)]
|
|
106
142
|
pub(super) struct Completed {}
|
|
@@ -123,44 +159,50 @@ pub(super) struct StartCommandCreated {}
|
|
|
123
159
|
impl StartCommandCreated {
|
|
124
160
|
pub(super) fn on_start_child_workflow_execution_initiated(
|
|
125
161
|
self,
|
|
126
|
-
state: SharedState,
|
|
127
|
-
|
|
162
|
+
state: &mut SharedState,
|
|
163
|
+
event_dat: ChildWorkflowInitiatedData,
|
|
128
164
|
) -> ChildWorkflowMachineTransition<StartEventRecorded> {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
165
|
+
if state.internal_flags.borrow_mut().try_use(
|
|
166
|
+
CoreInternalFlags::IdAndTypeDeterminismChecks,
|
|
167
|
+
event_dat.last_task_in_history,
|
|
168
|
+
) {
|
|
169
|
+
if event_dat.wf_id != state.workflow_id {
|
|
170
|
+
return TransitionResult::Err(WFMachinesError::Nondeterminism(format!(
|
|
171
|
+
"Child workflow id of scheduled event '{}' does not \
|
|
172
|
+
match child workflow id of activity command '{}'",
|
|
173
|
+
event_dat.wf_id, state.workflow_id
|
|
174
|
+
)));
|
|
175
|
+
}
|
|
176
|
+
if event_dat.wf_type != state.workflow_type {
|
|
177
|
+
return TransitionResult::Err(WFMachinesError::Nondeterminism(format!(
|
|
178
|
+
"Child workflow type of scheduled event '{}' does not \
|
|
179
|
+
match child workflow type of activity command '{}'",
|
|
180
|
+
event_dat.wf_type, state.workflow_type
|
|
181
|
+
)));
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
state.initiated_event_id = event_dat.event_id;
|
|
185
|
+
ChildWorkflowMachineTransition::default()
|
|
137
186
|
}
|
|
138
187
|
|
|
139
188
|
pub(super) fn on_cancelled(
|
|
140
189
|
self,
|
|
141
|
-
state: SharedState,
|
|
190
|
+
state: &mut SharedState,
|
|
142
191
|
) -> ChildWorkflowMachineTransition<Cancelled> {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
failure::CanceledFailureInfo {
|
|
153
|
-
..Default::default()
|
|
154
|
-
},
|
|
155
|
-
)),
|
|
156
|
-
..Default::default()
|
|
157
|
-
})),
|
|
158
|
-
failure_info: failure_info_from_state(&state, RetryState::NonRetryableFailure),
|
|
192
|
+
state.cancelled_before_sent = true;
|
|
193
|
+
ChildWorkflowMachineTransition::commands(vec![ChildWorkflowCommand::StartCancel(Failure {
|
|
194
|
+
message: "Child Workflow execution cancelled before scheduled".to_owned(),
|
|
195
|
+
cause: Some(Box::new(Failure {
|
|
196
|
+
failure_info: Some(FailureInfo::CanceledFailureInfo(
|
|
197
|
+
failure::CanceledFailureInfo {
|
|
198
|
+
..Default::default()
|
|
199
|
+
},
|
|
200
|
+
)),
|
|
159
201
|
..Default::default()
|
|
160
|
-
})
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
)
|
|
202
|
+
})),
|
|
203
|
+
failure_info: failure_info_from_state(state, RetryState::NonRetryableFailure),
|
|
204
|
+
..Default::default()
|
|
205
|
+
})])
|
|
164
206
|
}
|
|
165
207
|
}
|
|
166
208
|
|
|
@@ -170,20 +212,14 @@ pub(super) struct StartEventRecorded {}
|
|
|
170
212
|
impl StartEventRecorded {
|
|
171
213
|
pub(super) fn on_child_workflow_execution_started(
|
|
172
214
|
self,
|
|
173
|
-
state: SharedState,
|
|
215
|
+
state: &mut SharedState,
|
|
174
216
|
event: ChildWorkflowExecutionStartedEvent,
|
|
175
217
|
) -> ChildWorkflowMachineTransition<Started> {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
SharedState {
|
|
182
|
-
started_event_id: event.started_event_id,
|
|
183
|
-
run_id: event.workflow_execution.run_id,
|
|
184
|
-
..state
|
|
185
|
-
},
|
|
186
|
-
)
|
|
218
|
+
state.started_event_id = event.started_event_id;
|
|
219
|
+
state.run_id = event.workflow_execution.run_id.clone();
|
|
220
|
+
ChildWorkflowMachineTransition::commands(vec![ChildWorkflowCommand::Start(
|
|
221
|
+
event.workflow_execution,
|
|
222
|
+
)])
|
|
187
223
|
}
|
|
188
224
|
pub(super) fn on_start_child_workflow_execution_failed(
|
|
189
225
|
self,
|
|
@@ -214,13 +250,13 @@ impl Started {
|
|
|
214
250
|
}
|
|
215
251
|
fn on_child_workflow_execution_failed(
|
|
216
252
|
self,
|
|
217
|
-
state: SharedState,
|
|
253
|
+
state: &mut SharedState,
|
|
218
254
|
attrs: ChildWorkflowExecutionFailedEventAttributes,
|
|
219
255
|
) -> ChildWorkflowMachineTransition<Failed> {
|
|
220
256
|
ChildWorkflowMachineTransition::ok(
|
|
221
257
|
vec![ChildWorkflowCommand::Fail(Failure {
|
|
222
258
|
message: "Child Workflow execution failed".to_owned(),
|
|
223
|
-
failure_info: failure_info_from_state(
|
|
259
|
+
failure_info: failure_info_from_state(state, attrs.retry_state()),
|
|
224
260
|
cause: attrs.failure.map(Box::new),
|
|
225
261
|
..Default::default()
|
|
226
262
|
})],
|
|
@@ -229,7 +265,7 @@ impl Started {
|
|
|
229
265
|
}
|
|
230
266
|
fn on_child_workflow_execution_timed_out(
|
|
231
267
|
self,
|
|
232
|
-
state: SharedState,
|
|
268
|
+
state: &mut SharedState,
|
|
233
269
|
retry_state: RetryState,
|
|
234
270
|
) -> ChildWorkflowMachineTransition<TimedOut> {
|
|
235
271
|
ChildWorkflowMachineTransition::ok(
|
|
@@ -245,18 +281,23 @@ impl Started {
|
|
|
245
281
|
)),
|
|
246
282
|
..Default::default()
|
|
247
283
|
})),
|
|
248
|
-
failure_info: failure_info_from_state(
|
|
284
|
+
failure_info: failure_info_from_state(state, retry_state),
|
|
249
285
|
..Default::default()
|
|
250
286
|
})],
|
|
251
287
|
TimedOut::default(),
|
|
252
288
|
)
|
|
253
289
|
}
|
|
254
290
|
fn on_child_workflow_execution_cancelled(self) -> ChildWorkflowMachineTransition<Cancelled> {
|
|
255
|
-
ChildWorkflowMachineTransition::ok(
|
|
291
|
+
ChildWorkflowMachineTransition::ok(
|
|
292
|
+
vec![ChildWorkflowCommand::Cancel],
|
|
293
|
+
Cancelled {
|
|
294
|
+
seen_cancelled_event: true,
|
|
295
|
+
},
|
|
296
|
+
)
|
|
256
297
|
}
|
|
257
298
|
fn on_child_workflow_execution_terminated(
|
|
258
299
|
self,
|
|
259
|
-
state: SharedState,
|
|
300
|
+
state: &mut SharedState,
|
|
260
301
|
) -> ChildWorkflowMachineTransition<Terminated> {
|
|
261
302
|
ChildWorkflowMachineTransition::ok(
|
|
262
303
|
vec![ChildWorkflowCommand::Fail(Failure {
|
|
@@ -268,7 +309,7 @@ impl Started {
|
|
|
268
309
|
)),
|
|
269
310
|
..Default::default()
|
|
270
311
|
})),
|
|
271
|
-
failure_info: failure_info_from_state(
|
|
312
|
+
failure_info: failure_info_from_state(state, RetryState::NonRetryableFailure),
|
|
272
313
|
..Default::default()
|
|
273
314
|
})],
|
|
274
315
|
Terminated::default(),
|
|
@@ -276,7 +317,7 @@ impl Started {
|
|
|
276
317
|
}
|
|
277
318
|
fn on_cancelled(
|
|
278
319
|
self,
|
|
279
|
-
state: SharedState,
|
|
320
|
+
state: &mut SharedState,
|
|
280
321
|
) -> ChildWorkflowMachineTransition<StartedOrCancelled> {
|
|
281
322
|
let dest = match state.cancel_type {
|
|
282
323
|
ChildWorkflowCancellationType::Abandon | ChildWorkflowCancellationType::TryCancel => {
|
|
@@ -299,7 +340,7 @@ pub(super) struct Terminated {}
|
|
|
299
340
|
#[derive(Default, Clone)]
|
|
300
341
|
pub(super) struct TimedOut {}
|
|
301
342
|
|
|
302
|
-
#[derive(
|
|
343
|
+
#[derive(Clone, Debug)]
|
|
303
344
|
pub(super) struct SharedState {
|
|
304
345
|
initiated_event_id: i64,
|
|
305
346
|
started_event_id: i64,
|
|
@@ -310,38 +351,40 @@ pub(super) struct SharedState {
|
|
|
310
351
|
workflow_type: String,
|
|
311
352
|
cancelled_before_sent: bool,
|
|
312
353
|
cancel_type: ChildWorkflowCancellationType,
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
/// Creates a new child workflow state machine and a command to start it on the server.
|
|
316
|
-
pub(super) fn new_child_workflow(attribs: StartChildWorkflowExecution) -> NewMachineWithCommand {
|
|
317
|
-
let (wf, add_cmd) = ChildWorkflowMachine::new_scheduled(attribs);
|
|
318
|
-
NewMachineWithCommand {
|
|
319
|
-
command: add_cmd,
|
|
320
|
-
machine: wf.into(),
|
|
321
|
-
}
|
|
354
|
+
internal_flags: InternalFlagsRef,
|
|
322
355
|
}
|
|
323
356
|
|
|
324
357
|
impl ChildWorkflowMachine {
|
|
325
358
|
/// Create a new child workflow and immediately schedule it.
|
|
326
|
-
pub(
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
359
|
+
pub(super) fn new_scheduled(
|
|
360
|
+
attribs: StartChildWorkflowExecution,
|
|
361
|
+
internal_flags: InternalFlagsRef,
|
|
362
|
+
) -> NewMachineWithCommand {
|
|
363
|
+
let mut s = Self::from_parts(
|
|
364
|
+
Created {}.into(),
|
|
365
|
+
SharedState {
|
|
330
366
|
lang_sequence_number: attribs.seq,
|
|
331
367
|
workflow_id: attribs.workflow_id.clone(),
|
|
332
368
|
workflow_type: attribs.workflow_type.clone(),
|
|
333
369
|
namespace: attribs.namespace.clone(),
|
|
334
370
|
cancel_type: attribs.cancellation_type(),
|
|
335
|
-
|
|
371
|
+
internal_flags,
|
|
372
|
+
run_id: "".to_string(),
|
|
373
|
+
initiated_event_id: 0,
|
|
374
|
+
started_event_id: 0,
|
|
375
|
+
cancelled_before_sent: false,
|
|
336
376
|
},
|
|
337
|
-
|
|
377
|
+
);
|
|
338
378
|
OnEventWrapper::on_event_mut(&mut s, ChildWorkflowMachineEvents::Schedule)
|
|
339
379
|
.expect("Scheduling child workflows doesn't fail");
|
|
340
380
|
let cmd = Command {
|
|
341
381
|
command_type: CommandType::StartChildWorkflowExecution as i32,
|
|
342
382
|
attributes: Some(attribs.into()),
|
|
343
383
|
};
|
|
344
|
-
|
|
384
|
+
NewMachineWithCommand {
|
|
385
|
+
command: cmd,
|
|
386
|
+
machine: s.into(),
|
|
387
|
+
}
|
|
345
388
|
}
|
|
346
389
|
|
|
347
390
|
fn resolve_cancelled_msg(&self) -> ResolveChildWorkflowExecution {
|
|
@@ -372,13 +415,31 @@ impl ChildWorkflowMachine {
|
|
|
372
415
|
}
|
|
373
416
|
}
|
|
374
417
|
|
|
375
|
-
impl TryFrom<
|
|
418
|
+
impl TryFrom<HistEventData> for ChildWorkflowMachineEvents {
|
|
376
419
|
type Error = WFMachinesError;
|
|
377
420
|
|
|
378
|
-
fn try_from(e:
|
|
421
|
+
fn try_from(e: HistEventData) -> Result<Self, Self::Error> {
|
|
422
|
+
let last_task_in_history = e.current_task_is_last_in_history;
|
|
423
|
+
let e = e.event;
|
|
379
424
|
Ok(match EventType::from_i32(e.event_type) {
|
|
380
425
|
Some(EventType::StartChildWorkflowExecutionInitiated) => {
|
|
381
|
-
|
|
426
|
+
if let Some(
|
|
427
|
+
history_event::Attributes::StartChildWorkflowExecutionInitiatedEventAttributes(
|
|
428
|
+
attrs,
|
|
429
|
+
),
|
|
430
|
+
) = e.attributes
|
|
431
|
+
{
|
|
432
|
+
Self::StartChildWorkflowExecutionInitiated(ChildWorkflowInitiatedData {
|
|
433
|
+
event_id: e.event_id,
|
|
434
|
+
wf_type: attrs.workflow_type.unwrap_or_default().name,
|
|
435
|
+
wf_id: attrs.workflow_id,
|
|
436
|
+
last_task_in_history,
|
|
437
|
+
})
|
|
438
|
+
} else {
|
|
439
|
+
return Err(WFMachinesError::Fatal(
|
|
440
|
+
"StartChildWorkflowExecutionInitiated attributes were unset".to_string(),
|
|
441
|
+
));
|
|
442
|
+
}
|
|
382
443
|
}
|
|
383
444
|
Some(EventType::StartChildWorkflowExecutionFailed) => {
|
|
384
445
|
if let Some(
|
|
@@ -471,8 +532,7 @@ impl TryFrom<HistoryEvent> for ChildWorkflowMachineEvents {
|
|
|
471
532
|
}
|
|
472
533
|
_ => {
|
|
473
534
|
return Err(WFMachinesError::Fatal(format!(
|
|
474
|
-
"Child workflow machine does not handle this event: {:?}"
|
|
475
|
-
e
|
|
535
|
+
"Child workflow machine does not handle this event: {e:?}"
|
|
476
536
|
)))
|
|
477
537
|
}
|
|
478
538
|
})
|
|
@@ -612,7 +672,7 @@ impl Cancellable for ChildWorkflowMachine {
|
|
|
612
672
|
| c @ ChildWorkflowCommand::IssueCancelAfterStarted { .. } => {
|
|
613
673
|
self.adapt_response(c, None)
|
|
614
674
|
}
|
|
615
|
-
x => panic!("Invalid cancel event response {:?}"
|
|
675
|
+
x => panic!("Invalid cancel event response {x:?}"),
|
|
616
676
|
})
|
|
617
677
|
.collect::<Result<Vec<_>, _>>()?
|
|
618
678
|
.into_iter()
|
|
@@ -650,8 +710,7 @@ fn convert_payloads(
|
|
|
650
710
|
) -> Result<Option<Payload>, WFMachinesError> {
|
|
651
711
|
result.map(TryInto::try_into).transpose().map_err(|pe| {
|
|
652
712
|
WFMachinesError::Fatal(format!(
|
|
653
|
-
"Not exactly one payload in child workflow result ({}) for event: {:?}"
|
|
654
|
-
pe, event_info
|
|
713
|
+
"Not exactly one payload in child workflow result ({pe}) for event: {event_info:?}"
|
|
655
714
|
))
|
|
656
715
|
})
|
|
657
716
|
}
|
|
@@ -660,11 +719,12 @@ fn convert_payloads(
|
|
|
660
719
|
mod test {
|
|
661
720
|
use super::*;
|
|
662
721
|
use crate::{
|
|
663
|
-
replay::TestHistoryBuilder, test_help::canned_histories,
|
|
722
|
+
internal_flags::InternalFlags, replay::TestHistoryBuilder, test_help::canned_histories,
|
|
723
|
+
worker::workflow::ManagedWFFunc,
|
|
664
724
|
};
|
|
665
725
|
use anyhow::anyhow;
|
|
666
726
|
use rstest::{fixture, rstest};
|
|
667
|
-
use std::mem::discriminant;
|
|
727
|
+
use std::{cell::RefCell, mem::discriminant, rc::Rc};
|
|
668
728
|
use temporal_sdk::{
|
|
669
729
|
CancellableFuture, ChildWorkflowOptions, WfContext, WorkflowFunction, WorkflowResult,
|
|
670
730
|
};
|
|
@@ -840,19 +900,32 @@ mod test {
|
|
|
840
900
|
#[test]
|
|
841
901
|
fn cancels_ignored_terminal() {
|
|
842
902
|
for state in [
|
|
843
|
-
ChildWorkflowMachineState::Cancelled(Cancelled {
|
|
903
|
+
ChildWorkflowMachineState::Cancelled(Cancelled {
|
|
904
|
+
seen_cancelled_event: false,
|
|
905
|
+
}),
|
|
844
906
|
Failed {}.into(),
|
|
845
907
|
StartFailed {}.into(),
|
|
846
908
|
TimedOut {}.into(),
|
|
847
909
|
Completed {}.into(),
|
|
848
910
|
] {
|
|
849
|
-
let mut s = ChildWorkflowMachine
|
|
850
|
-
state
|
|
851
|
-
|
|
852
|
-
|
|
911
|
+
let mut s = ChildWorkflowMachine::from_parts(
|
|
912
|
+
state.clone(),
|
|
913
|
+
SharedState {
|
|
914
|
+
initiated_event_id: 0,
|
|
915
|
+
started_event_id: 0,
|
|
916
|
+
lang_sequence_number: 0,
|
|
917
|
+
namespace: "".to_string(),
|
|
918
|
+
workflow_id: "".to_string(),
|
|
919
|
+
run_id: "".to_string(),
|
|
920
|
+
workflow_type: "".to_string(),
|
|
921
|
+
cancelled_before_sent: false,
|
|
922
|
+
cancel_type: Default::default(),
|
|
923
|
+
internal_flags: Rc::new(RefCell::new(InternalFlags::new(&Default::default()))),
|
|
924
|
+
},
|
|
925
|
+
);
|
|
853
926
|
let cmds = s.cancel().unwrap();
|
|
854
927
|
assert_eq!(cmds.len(), 0);
|
|
855
|
-
assert_eq!(discriminant(&state), discriminant(
|
|
928
|
+
assert_eq!(discriminant(&state), discriminant(s.state()));
|
|
856
929
|
}
|
|
857
930
|
}
|
|
858
931
|
}
|
|
@@ -2,7 +2,8 @@ use super::{
|
|
|
2
2
|
workflow_machines::MachineResponse, Cancellable, EventInfo, NewMachineWithCommand,
|
|
3
3
|
OnEventWrapper, WFMachinesAdapter, WFMachinesError,
|
|
4
4
|
};
|
|
5
|
-
use
|
|
5
|
+
use crate::worker::workflow::machines::HistEventData;
|
|
6
|
+
use rustfsm::{fsm, StateMachine, TransitionResult};
|
|
6
7
|
use std::convert::TryFrom;
|
|
7
8
|
use temporal_sdk_core_protos::{
|
|
8
9
|
coresdk::workflow_commands::CompleteWorkflowExecution,
|
|
@@ -18,9 +19,9 @@ fsm! {
|
|
|
18
19
|
name CompleteWorkflowMachine;
|
|
19
20
|
command CompleteWFCommand;
|
|
20
21
|
error WFMachinesError;
|
|
21
|
-
shared_state
|
|
22
|
+
shared_state ();
|
|
22
23
|
|
|
23
|
-
Created --(Schedule,
|
|
24
|
+
Created --(Schedule, on_schedule) --> CompleteWorkflowCommandCreated;
|
|
24
25
|
|
|
25
26
|
CompleteWorkflowCommandCreated --(CommandCompleteWorkflowExecution)
|
|
26
27
|
--> CompleteWorkflowCommandCreated;
|
|
@@ -45,10 +46,7 @@ pub(super) fn complete_workflow(attribs: CompleteWorkflowExecution) -> NewMachin
|
|
|
45
46
|
impl CompleteWorkflowMachine {
|
|
46
47
|
/// Create a new WF machine and schedule it
|
|
47
48
|
pub(crate) fn new_scheduled(attribs: CompleteWorkflowExecution) -> (Self, Command) {
|
|
48
|
-
let mut s = Self {
|
|
49
|
-
state: Created {}.into(),
|
|
50
|
-
shared_state: attribs,
|
|
51
|
-
};
|
|
49
|
+
let mut s = Self::from_parts(Created { attribs }.into(), ());
|
|
52
50
|
let cmd =
|
|
53
51
|
match OnEventWrapper::on_event_mut(&mut s, CompleteWorkflowMachineEvents::Schedule)
|
|
54
52
|
.expect("Scheduling complete wf machines doesn't fail")
|
|
@@ -61,16 +59,16 @@ impl CompleteWorkflowMachine {
|
|
|
61
59
|
}
|
|
62
60
|
}
|
|
63
61
|
|
|
64
|
-
impl TryFrom<
|
|
62
|
+
impl TryFrom<HistEventData> for CompleteWorkflowMachineEvents {
|
|
65
63
|
type Error = WFMachinesError;
|
|
66
64
|
|
|
67
|
-
fn try_from(e:
|
|
65
|
+
fn try_from(e: HistEventData) -> Result<Self, Self::Error> {
|
|
66
|
+
let e = e.event;
|
|
68
67
|
Ok(match e.event_type() {
|
|
69
68
|
EventType::WorkflowExecutionCompleted => Self::WorkflowExecutionCompleted,
|
|
70
69
|
_ => {
|
|
71
70
|
return Err(WFMachinesError::Nondeterminism(format!(
|
|
72
|
-
"Complete workflow machine does not handle this event: {}"
|
|
73
|
-
e
|
|
71
|
+
"Complete workflow machine does not handle this event: {e}"
|
|
74
72
|
)))
|
|
75
73
|
}
|
|
76
74
|
})
|
|
@@ -89,16 +87,17 @@ impl TryFrom<CommandType> for CompleteWorkflowMachineEvents {
|
|
|
89
87
|
}
|
|
90
88
|
|
|
91
89
|
#[derive(Default, Clone)]
|
|
92
|
-
pub(super) struct Created {
|
|
90
|
+
pub(super) struct Created {
|
|
91
|
+
attribs: CompleteWorkflowExecution,
|
|
92
|
+
}
|
|
93
93
|
|
|
94
94
|
impl Created {
|
|
95
95
|
pub(super) fn on_schedule(
|
|
96
96
|
self,
|
|
97
|
-
dat: CompleteWorkflowExecution,
|
|
98
97
|
) -> CompleteWorkflowMachineTransition<CompleteWorkflowCommandCreated> {
|
|
99
98
|
let cmd = Command {
|
|
100
99
|
command_type: CommandType::CompleteWorkflowExecution as i32,
|
|
101
|
-
attributes: Some(
|
|
100
|
+
attributes: Some(self.attribs.into()),
|
|
102
101
|
};
|
|
103
102
|
TransitionResult::commands(vec![CompleteWFCommand::AddCommand(cmd)])
|
|
104
103
|
}
|
package/sdk-core/core/src/worker/workflow/machines/continue_as_new_workflow_state_machine.rs
CHANGED
|
@@ -2,7 +2,8 @@ use super::{
|
|
|
2
2
|
Cancellable, EventInfo, HistoryEvent, MachineResponse, NewMachineWithCommand, OnEventWrapper,
|
|
3
3
|
WFMachinesAdapter, WFMachinesError,
|
|
4
4
|
};
|
|
5
|
-
use
|
|
5
|
+
use crate::worker::workflow::machines::HistEventData;
|
|
6
|
+
use rustfsm::{fsm, StateMachine, TransitionResult};
|
|
6
7
|
use std::convert::TryFrom;
|
|
7
8
|
use temporal_sdk_core_protos::{
|
|
8
9
|
coresdk::workflow_commands::ContinueAsNewWorkflowExecution,
|
|
@@ -30,10 +31,7 @@ fsm! {
|
|
|
30
31
|
pub(super) enum ContinueAsNewWorkflowCommand {}
|
|
31
32
|
|
|
32
33
|
pub(super) fn continue_as_new(attribs: ContinueAsNewWorkflowExecution) -> NewMachineWithCommand {
|
|
33
|
-
let mut machine = ContinueAsNewWorkflowMachine {
|
|
34
|
-
state: Created {}.into(),
|
|
35
|
-
shared_state: (),
|
|
36
|
-
};
|
|
34
|
+
let mut machine = ContinueAsNewWorkflowMachine::from_parts(Created {}.into(), ());
|
|
37
35
|
OnEventWrapper::on_event_mut(&mut machine, ContinueAsNewWorkflowMachineEvents::Schedule)
|
|
38
36
|
.expect("Scheduling continue as new machine doesn't fail");
|
|
39
37
|
let command = Command {
|
|
@@ -69,16 +67,16 @@ impl From<ContinueAsNewWorkflowCommandCreated> for ContinueAsNewWorkflowCommandR
|
|
|
69
67
|
}
|
|
70
68
|
}
|
|
71
69
|
|
|
72
|
-
impl TryFrom<
|
|
70
|
+
impl TryFrom<HistEventData> for ContinueAsNewWorkflowMachineEvents {
|
|
73
71
|
type Error = WFMachinesError;
|
|
74
72
|
|
|
75
|
-
fn try_from(e:
|
|
73
|
+
fn try_from(e: HistEventData) -> Result<Self, Self::Error> {
|
|
74
|
+
let e = e.event;
|
|
76
75
|
Ok(match e.event_type() {
|
|
77
76
|
EventType::WorkflowExecutionContinuedAsNew => Self::WorkflowExecutionContinuedAsNew,
|
|
78
77
|
_ => {
|
|
79
78
|
return Err(WFMachinesError::Nondeterminism(format!(
|
|
80
|
-
"Continue as new workflow machine does not handle this event: {}"
|
|
81
|
-
e
|
|
79
|
+
"Continue as new workflow machine does not handle this event: {e}"
|
|
82
80
|
)))
|
|
83
81
|
}
|
|
84
82
|
})
|