@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
|
@@ -4,6 +4,10 @@ use super::{
|
|
|
4
4
|
workflow_machines::MachineResponse, Cancellable, EventInfo, NewMachineWithCommand,
|
|
5
5
|
OnEventWrapper, WFMachinesAdapter, WFMachinesError,
|
|
6
6
|
};
|
|
7
|
+
use crate::{
|
|
8
|
+
internal_flags::CoreInternalFlags,
|
|
9
|
+
worker::workflow::{machines::HistEventData, InternalFlagsRef},
|
|
10
|
+
};
|
|
7
11
|
use rustfsm::{fsm, MachineError, StateMachine, TransitionResult};
|
|
8
12
|
use std::convert::{TryFrom, TryInto};
|
|
9
13
|
use temporal_sdk_core_protos::{
|
|
@@ -16,10 +20,7 @@ use temporal_sdk_core_protos::{
|
|
|
16
20
|
command::v1::{command, Command, RequestCancelActivityTaskCommandAttributes},
|
|
17
21
|
common::v1::{ActivityType, Payload, Payloads},
|
|
18
22
|
enums::v1::{CommandType, EventType, RetryState},
|
|
19
|
-
failure::v1::{
|
|
20
|
-
self as failure, failure::FailureInfo, ActivityFailureInfo, CanceledFailureInfo,
|
|
21
|
-
Failure,
|
|
22
|
-
},
|
|
23
|
+
failure::v1::{failure::FailureInfo, ActivityFailureInfo, CanceledFailureInfo, Failure},
|
|
23
24
|
history::v1::{
|
|
24
25
|
history_event, ActivityTaskCanceledEventAttributes,
|
|
25
26
|
ActivityTaskCompletedEventAttributes, ActivityTaskFailedEventAttributes,
|
|
@@ -37,7 +38,7 @@ fsm! {
|
|
|
37
38
|
Created --(Schedule, on_schedule)--> ScheduleCommandCreated;
|
|
38
39
|
|
|
39
40
|
ScheduleCommandCreated --(CommandScheduleActivityTask) --> ScheduleCommandCreated;
|
|
40
|
-
ScheduleCommandCreated --(ActivityTaskScheduled(
|
|
41
|
+
ScheduleCommandCreated --(ActivityTaskScheduled(ActTaskScheduledData),
|
|
41
42
|
shared on_activity_task_scheduled) --> ScheduledEventRecorded;
|
|
42
43
|
ScheduleCommandCreated --(Cancel, shared on_canceled) --> Canceled;
|
|
43
44
|
|
|
@@ -45,7 +46,7 @@ fsm! {
|
|
|
45
46
|
ScheduledEventRecorded --(ActivityTaskTimedOut(ActivityTaskTimedOutEventAttributes),
|
|
46
47
|
shared on_task_timed_out) --> TimedOut;
|
|
47
48
|
ScheduledEventRecorded --(Cancel, shared on_canceled) --> ScheduledActivityCancelCommandCreated;
|
|
48
|
-
ScheduledEventRecorded --(Abandon,
|
|
49
|
+
ScheduledEventRecorded --(Abandon, on_abandoned) --> Canceled;
|
|
49
50
|
|
|
50
51
|
Started --(ActivityTaskCompleted(ActivityTaskCompletedEventAttributes),
|
|
51
52
|
on_activity_task_completed) --> Completed;
|
|
@@ -54,7 +55,7 @@ fsm! {
|
|
|
54
55
|
Started --(ActivityTaskTimedOut(ActivityTaskTimedOutEventAttributes),
|
|
55
56
|
shared on_activity_task_timed_out) --> TimedOut;
|
|
56
57
|
Started --(Cancel, shared on_canceled) --> StartedActivityCancelCommandCreated;
|
|
57
|
-
Started --(Abandon,
|
|
58
|
+
Started --(Abandon, on_abandoned) --> Canceled;
|
|
58
59
|
|
|
59
60
|
ScheduledActivityCancelCommandCreated --(CommandRequestCancelActivityTask) --> ScheduledActivityCancelCommandCreated;
|
|
60
61
|
ScheduledActivityCancelCommandCreated --(ActivityTaskCancelRequested) --> ScheduledActivityCancelEventRecorded;
|
|
@@ -89,39 +90,46 @@ pub(super) enum ActivityMachineCommand {
|
|
|
89
90
|
#[display(fmt = "Fail")]
|
|
90
91
|
Fail(Failure),
|
|
91
92
|
#[display(fmt = "Cancel")]
|
|
92
|
-
Cancel(Option<
|
|
93
|
+
Cancel(Option<ActivityTaskCanceledEventAttributes>),
|
|
93
94
|
#[display(fmt = "RequestCancellation")]
|
|
94
95
|
RequestCancellation(Command),
|
|
95
96
|
}
|
|
96
97
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
machine: activity.into(),
|
|
103
|
-
}
|
|
98
|
+
pub(super) struct ActTaskScheduledData {
|
|
99
|
+
event_id: i64,
|
|
100
|
+
act_type: String,
|
|
101
|
+
act_id: String,
|
|
102
|
+
last_task_in_history: bool,
|
|
104
103
|
}
|
|
105
104
|
|
|
106
105
|
impl ActivityMachine {
|
|
107
106
|
/// Create a new activity and immediately schedule it.
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
107
|
+
pub(super) fn new_scheduled(
|
|
108
|
+
attrs: ScheduleActivity,
|
|
109
|
+
internal_flags: InternalFlagsRef,
|
|
110
|
+
) -> NewMachineWithCommand {
|
|
111
|
+
let mut s = Self::from_parts(
|
|
112
|
+
Created {}.into(),
|
|
113
|
+
SharedState {
|
|
114
|
+
cancellation_type: ActivityCancellationType::from_i32(attrs.cancellation_type)
|
|
113
115
|
.unwrap(),
|
|
114
|
-
attrs
|
|
115
|
-
|
|
116
|
+
attrs,
|
|
117
|
+
internal_flags,
|
|
118
|
+
scheduled_event_id: 0,
|
|
119
|
+
started_event_id: 0,
|
|
120
|
+
cancelled_before_sent: false,
|
|
116
121
|
},
|
|
117
|
-
|
|
122
|
+
);
|
|
118
123
|
OnEventWrapper::on_event_mut(&mut s, ActivityMachineEvents::Schedule)
|
|
119
124
|
.expect("Scheduling activities doesn't fail");
|
|
120
|
-
let
|
|
125
|
+
let command = Command {
|
|
121
126
|
command_type: CommandType::ScheduleActivityTask as i32,
|
|
122
127
|
attributes: Some(s.shared_state().attrs.clone().into()),
|
|
123
128
|
};
|
|
124
|
-
|
|
129
|
+
NewMachineWithCommand {
|
|
130
|
+
command,
|
|
131
|
+
machine: s.into(),
|
|
132
|
+
}
|
|
125
133
|
}
|
|
126
134
|
|
|
127
135
|
fn machine_responses_from_cancel_request(&self, cancel_cmd: Command) -> Vec<MachineResponse> {
|
|
@@ -136,45 +144,46 @@ impl ActivityMachine {
|
|
|
136
144
|
r
|
|
137
145
|
}
|
|
138
146
|
|
|
139
|
-
fn create_cancelation_resolve(
|
|
147
|
+
fn create_cancelation_resolve(
|
|
148
|
+
&self,
|
|
149
|
+
attrs: Option<ActivityTaskCanceledEventAttributes>,
|
|
150
|
+
) -> ResolveActivity {
|
|
151
|
+
let attrs = attrs.unwrap_or_default();
|
|
140
152
|
ResolveActivity {
|
|
141
153
|
seq: self.shared_state.attrs.seq,
|
|
142
154
|
result: Some(ActivityResolution {
|
|
143
155
|
status: Some(activity_resolution::Status::Cancelled(Cancellation {
|
|
144
|
-
failure: Some(
|
|
145
|
-
message: "Activity cancelled".to_string(),
|
|
146
|
-
cause: Some(Box::from(Failure {
|
|
147
|
-
failure_info: Some(FailureInfo::CanceledFailureInfo(
|
|
148
|
-
CanceledFailureInfo {
|
|
149
|
-
details: details.map(Into::into),
|
|
150
|
-
},
|
|
151
|
-
)),
|
|
152
|
-
..Default::default()
|
|
153
|
-
})),
|
|
154
|
-
failure_info: Some(FailureInfo::ActivityFailureInfo(ActivityFailureInfo {
|
|
155
|
-
scheduled_event_id: self.shared_state.scheduled_event_id,
|
|
156
|
-
started_event_id: self.shared_state.started_event_id,
|
|
157
|
-
activity_type: Some(ActivityType {
|
|
158
|
-
name: self.shared_state.attrs.activity_type.clone(),
|
|
159
|
-
}),
|
|
160
|
-
activity_id: self.shared_state.attrs.activity_id.clone(),
|
|
161
|
-
retry_state: RetryState::CancelRequested as i32,
|
|
162
|
-
..Default::default()
|
|
163
|
-
})),
|
|
164
|
-
..Default::default()
|
|
165
|
-
}),
|
|
156
|
+
failure: Some(new_cancel_failure(&self.shared_state, attrs)),
|
|
166
157
|
})),
|
|
167
158
|
}),
|
|
168
159
|
}
|
|
169
160
|
}
|
|
170
161
|
}
|
|
171
162
|
|
|
172
|
-
impl TryFrom<
|
|
163
|
+
impl TryFrom<HistEventData> for ActivityMachineEvents {
|
|
173
164
|
type Error = WFMachinesError;
|
|
174
165
|
|
|
175
|
-
fn try_from(e:
|
|
166
|
+
fn try_from(e: HistEventData) -> Result<Self, Self::Error> {
|
|
167
|
+
let last_task_in_history = e.current_task_is_last_in_history;
|
|
168
|
+
let e = e.event;
|
|
176
169
|
Ok(match e.event_type() {
|
|
177
|
-
EventType::ActivityTaskScheduled =>
|
|
170
|
+
EventType::ActivityTaskScheduled => {
|
|
171
|
+
if let Some(history_event::Attributes::ActivityTaskScheduledEventAttributes(
|
|
172
|
+
attrs,
|
|
173
|
+
)) = e.attributes
|
|
174
|
+
{
|
|
175
|
+
Self::ActivityTaskScheduled(ActTaskScheduledData {
|
|
176
|
+
event_id: e.event_id,
|
|
177
|
+
act_id: attrs.activity_id,
|
|
178
|
+
act_type: attrs.activity_type.unwrap_or_default().name,
|
|
179
|
+
last_task_in_history,
|
|
180
|
+
})
|
|
181
|
+
} else {
|
|
182
|
+
return Err(WFMachinesError::Fatal(format!(
|
|
183
|
+
"Activity scheduled attributes were unset: {e}"
|
|
184
|
+
)));
|
|
185
|
+
}
|
|
186
|
+
}
|
|
178
187
|
EventType::ActivityTaskStarted => Self::ActivityTaskStarted(e.event_id),
|
|
179
188
|
EventType::ActivityTaskCompleted => {
|
|
180
189
|
if let Some(history_event::Attributes::ActivityTaskCompletedEventAttributes(
|
|
@@ -184,8 +193,7 @@ impl TryFrom<HistoryEvent> for ActivityMachineEvents {
|
|
|
184
193
|
Self::ActivityTaskCompleted(attrs)
|
|
185
194
|
} else {
|
|
186
195
|
return Err(WFMachinesError::Fatal(format!(
|
|
187
|
-
"Activity completion attributes were unset: {}"
|
|
188
|
-
e
|
|
196
|
+
"Activity completion attributes were unset: {e}"
|
|
189
197
|
)));
|
|
190
198
|
}
|
|
191
199
|
}
|
|
@@ -196,8 +204,7 @@ impl TryFrom<HistoryEvent> for ActivityMachineEvents {
|
|
|
196
204
|
Self::ActivityTaskFailed(attrs)
|
|
197
205
|
} else {
|
|
198
206
|
return Err(WFMachinesError::Fatal(format!(
|
|
199
|
-
"Activity failure attributes were unset: {}"
|
|
200
|
-
e
|
|
207
|
+
"Activity failure attributes were unset: {e}"
|
|
201
208
|
)));
|
|
202
209
|
}
|
|
203
210
|
}
|
|
@@ -208,8 +215,7 @@ impl TryFrom<HistoryEvent> for ActivityMachineEvents {
|
|
|
208
215
|
Self::ActivityTaskTimedOut(attrs)
|
|
209
216
|
} else {
|
|
210
217
|
return Err(WFMachinesError::Fatal(format!(
|
|
211
|
-
"Activity timeout attributes were unset: {}"
|
|
212
|
-
e
|
|
218
|
+
"Activity timeout attributes were unset: {e}"
|
|
213
219
|
)));
|
|
214
220
|
}
|
|
215
221
|
}
|
|
@@ -221,15 +227,13 @@ impl TryFrom<HistoryEvent> for ActivityMachineEvents {
|
|
|
221
227
|
Self::ActivityTaskCanceled(attrs)
|
|
222
228
|
} else {
|
|
223
229
|
return Err(WFMachinesError::Fatal(format!(
|
|
224
|
-
"Activity cancellation attributes were unset: {}"
|
|
225
|
-
e
|
|
230
|
+
"Activity cancellation attributes were unset: {e}"
|
|
226
231
|
)));
|
|
227
232
|
}
|
|
228
233
|
}
|
|
229
234
|
_ => {
|
|
230
235
|
return Err(WFMachinesError::Nondeterminism(format!(
|
|
231
|
-
"Activity machine does not handle this event: {}"
|
|
232
|
-
e
|
|
236
|
+
"Activity machine does not handle this event: {e}"
|
|
233
237
|
)))
|
|
234
238
|
}
|
|
235
239
|
})
|
|
@@ -268,10 +272,8 @@ impl WFMachinesAdapter for ActivityMachine {
|
|
|
268
272
|
ActivityMachineCommand::RequestCancellation(c) => {
|
|
269
273
|
self.machine_responses_from_cancel_request(c)
|
|
270
274
|
}
|
|
271
|
-
ActivityMachineCommand::Cancel(
|
|
272
|
-
vec![self
|
|
273
|
-
.create_cancelation_resolve(convert_payloads(event_info, details)?)
|
|
274
|
-
.into()]
|
|
275
|
+
ActivityMachineCommand::Cancel(attrs) => {
|
|
276
|
+
vec![self.create_cancelation_resolve(attrs).into()]
|
|
275
277
|
}
|
|
276
278
|
})
|
|
277
279
|
}
|
|
@@ -330,16 +332,9 @@ impl Cancellable for ActivityMachine {
|
|
|
330
332
|
self.machine_responses_from_cancel_request(cmd)
|
|
331
333
|
}
|
|
332
334
|
ActivityMachineCommand::Cancel(details) => {
|
|
333
|
-
vec![self
|
|
334
|
-
.create_cancelation_resolve(
|
|
335
|
-
details
|
|
336
|
-
.map(TryInto::try_into)
|
|
337
|
-
.transpose()
|
|
338
|
-
.unwrap_or_default(),
|
|
339
|
-
)
|
|
340
|
-
.into()]
|
|
335
|
+
vec![self.create_cancelation_resolve(details).into()]
|
|
341
336
|
}
|
|
342
|
-
x => panic!("Invalid cancel event response {:?}"
|
|
337
|
+
x => panic!("Invalid cancel event response {x:?}"),
|
|
343
338
|
})
|
|
344
339
|
.collect();
|
|
345
340
|
Ok(res)
|
|
@@ -350,13 +345,14 @@ impl Cancellable for ActivityMachine {
|
|
|
350
345
|
}
|
|
351
346
|
}
|
|
352
347
|
|
|
353
|
-
#[derive(
|
|
348
|
+
#[derive(Clone)]
|
|
354
349
|
pub(super) struct SharedState {
|
|
355
350
|
scheduled_event_id: i64,
|
|
356
351
|
started_event_id: i64,
|
|
357
352
|
attrs: ScheduleActivity,
|
|
358
353
|
cancellation_type: ActivityCancellationType,
|
|
359
354
|
cancelled_before_sent: bool,
|
|
355
|
+
internal_flags: InternalFlagsRef,
|
|
360
356
|
}
|
|
361
357
|
|
|
362
358
|
#[derive(Default, Clone)]
|
|
@@ -375,28 +371,37 @@ pub(super) struct ScheduleCommandCreated {}
|
|
|
375
371
|
impl ScheduleCommandCreated {
|
|
376
372
|
pub(super) fn on_activity_task_scheduled(
|
|
377
373
|
self,
|
|
378
|
-
dat: SharedState,
|
|
379
|
-
|
|
374
|
+
dat: &mut SharedState,
|
|
375
|
+
sched_dat: ActTaskScheduledData,
|
|
380
376
|
) -> ActivityMachineTransition<ScheduledEventRecorded> {
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
377
|
+
if dat.internal_flags.borrow_mut().try_use(
|
|
378
|
+
CoreInternalFlags::IdAndTypeDeterminismChecks,
|
|
379
|
+
sched_dat.last_task_in_history,
|
|
380
|
+
) {
|
|
381
|
+
if sched_dat.act_id != dat.attrs.activity_id {
|
|
382
|
+
return TransitionResult::Err(WFMachinesError::Nondeterminism(format!(
|
|
383
|
+
"Activity id of scheduled event '{}' does not \
|
|
384
|
+
match activity id of activity command '{}'",
|
|
385
|
+
sched_dat.act_id, dat.attrs.activity_id
|
|
386
|
+
)));
|
|
387
|
+
}
|
|
388
|
+
if sched_dat.act_type != dat.attrs.activity_type {
|
|
389
|
+
return TransitionResult::Err(WFMachinesError::Nondeterminism(format!(
|
|
390
|
+
"Activity type of scheduled event '{}' does not \
|
|
391
|
+
match activity type of activity command '{}'",
|
|
392
|
+
sched_dat.act_type, dat.attrs.activity_type
|
|
393
|
+
)));
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
dat.scheduled_event_id = sched_dat.event_id;
|
|
397
|
+
ActivityMachineTransition::default()
|
|
389
398
|
}
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
..dat
|
|
394
|
-
};
|
|
399
|
+
|
|
400
|
+
pub(super) fn on_canceled(self, dat: &mut SharedState) -> ActivityMachineTransition<Canceled> {
|
|
401
|
+
dat.cancelled_before_sent = true;
|
|
395
402
|
match dat.cancellation_type {
|
|
396
|
-
ActivityCancellationType::Abandon =>
|
|
397
|
-
|
|
398
|
-
}
|
|
399
|
-
_ => notify_lang_activity_cancelled(canceled_state, None),
|
|
403
|
+
ActivityCancellationType::Abandon => ActivityMachineTransition::default(),
|
|
404
|
+
_ => notify_lang_activity_cancelled(None),
|
|
400
405
|
}
|
|
401
406
|
}
|
|
402
407
|
}
|
|
@@ -407,21 +412,15 @@ pub(super) struct ScheduledEventRecorded {}
|
|
|
407
412
|
impl ScheduledEventRecorded {
|
|
408
413
|
pub(super) fn on_task_started(
|
|
409
414
|
self,
|
|
410
|
-
dat: SharedState,
|
|
415
|
+
dat: &mut SharedState,
|
|
411
416
|
started_event_id: i64,
|
|
412
417
|
) -> ActivityMachineTransition<Started> {
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
Started::default(),
|
|
416
|
-
SharedState {
|
|
417
|
-
started_event_id,
|
|
418
|
-
..dat
|
|
419
|
-
},
|
|
420
|
-
)
|
|
418
|
+
dat.started_event_id = started_event_id;
|
|
419
|
+
ActivityMachineTransition::default()
|
|
421
420
|
}
|
|
422
421
|
pub(super) fn on_task_timed_out(
|
|
423
422
|
self,
|
|
424
|
-
dat: SharedState,
|
|
423
|
+
dat: &mut SharedState,
|
|
425
424
|
attrs: ActivityTaskTimedOutEventAttributes,
|
|
426
425
|
) -> ActivityMachineTransition<TimedOut> {
|
|
427
426
|
notify_lang_activity_timed_out(dat, attrs)
|
|
@@ -429,15 +428,15 @@ impl ScheduledEventRecorded {
|
|
|
429
428
|
|
|
430
429
|
pub(super) fn on_canceled(
|
|
431
430
|
self,
|
|
432
|
-
dat: SharedState,
|
|
431
|
+
dat: &mut SharedState,
|
|
433
432
|
) -> ActivityMachineTransition<ScheduledActivityCancelCommandCreated> {
|
|
434
433
|
create_request_cancel_activity_task_command(
|
|
435
434
|
dat,
|
|
436
435
|
ScheduledActivityCancelCommandCreated::default(),
|
|
437
436
|
)
|
|
438
437
|
}
|
|
439
|
-
pub(super) fn on_abandoned(self
|
|
440
|
-
notify_lang_activity_cancelled(
|
|
438
|
+
pub(super) fn on_abandoned(self) -> ActivityMachineTransition<Canceled> {
|
|
439
|
+
notify_lang_activity_cancelled(None)
|
|
441
440
|
}
|
|
442
441
|
}
|
|
443
442
|
|
|
@@ -456,7 +455,7 @@ impl Started {
|
|
|
456
455
|
}
|
|
457
456
|
pub(super) fn on_activity_task_failed(
|
|
458
457
|
self,
|
|
459
|
-
dat: SharedState,
|
|
458
|
+
dat: &mut SharedState,
|
|
460
459
|
attrs: ActivityTaskFailedEventAttributes,
|
|
461
460
|
) -> ActivityMachineTransition<Failed> {
|
|
462
461
|
ActivityMachineTransition::ok(
|
|
@@ -467,7 +466,7 @@ impl Started {
|
|
|
467
466
|
|
|
468
467
|
pub(super) fn on_activity_task_timed_out(
|
|
469
468
|
self,
|
|
470
|
-
dat: SharedState,
|
|
469
|
+
dat: &mut SharedState,
|
|
471
470
|
attrs: ActivityTaskTimedOutEventAttributes,
|
|
472
471
|
) -> ActivityMachineTransition<TimedOut> {
|
|
473
472
|
notify_lang_activity_timed_out(dat, attrs)
|
|
@@ -475,15 +474,15 @@ impl Started {
|
|
|
475
474
|
|
|
476
475
|
pub(super) fn on_canceled(
|
|
477
476
|
self,
|
|
478
|
-
dat: SharedState,
|
|
477
|
+
dat: &mut SharedState,
|
|
479
478
|
) -> ActivityMachineTransition<StartedActivityCancelCommandCreated> {
|
|
480
479
|
create_request_cancel_activity_task_command(
|
|
481
480
|
dat,
|
|
482
481
|
StartedActivityCancelCommandCreated::default(),
|
|
483
482
|
)
|
|
484
483
|
}
|
|
485
|
-
pub(super) fn on_abandoned(self
|
|
486
|
-
notify_lang_activity_cancelled(
|
|
484
|
+
pub(super) fn on_abandoned(self) -> ActivityMachineTransition<Canceled> {
|
|
485
|
+
notify_lang_activity_cancelled(None)
|
|
487
486
|
}
|
|
488
487
|
}
|
|
489
488
|
|
|
@@ -496,15 +495,15 @@ pub(super) struct ScheduledActivityCancelEventRecorded {}
|
|
|
496
495
|
impl ScheduledActivityCancelEventRecorded {
|
|
497
496
|
pub(super) fn on_activity_task_canceled(
|
|
498
497
|
self,
|
|
499
|
-
dat: SharedState,
|
|
498
|
+
dat: &mut SharedState,
|
|
500
499
|
attrs: ActivityTaskCanceledEventAttributes,
|
|
501
500
|
) -> ActivityMachineTransition<Canceled> {
|
|
502
|
-
notify_if_not_already_cancelled(dat, |
|
|
501
|
+
notify_if_not_already_cancelled(dat, |_| notify_lang_activity_cancelled(Some(attrs)))
|
|
503
502
|
}
|
|
504
503
|
|
|
505
504
|
pub(super) fn on_activity_task_timed_out(
|
|
506
505
|
self,
|
|
507
|
-
dat: SharedState,
|
|
506
|
+
dat: &mut SharedState,
|
|
508
507
|
attrs: ActivityTaskTimedOutEventAttributes,
|
|
509
508
|
) -> ActivityMachineTransition<TimedOut> {
|
|
510
509
|
notify_if_not_already_cancelled(dat, |dat| notify_lang_activity_timed_out(dat, attrs))
|
|
@@ -526,7 +525,7 @@ pub(super) struct StartedActivityCancelEventRecorded {}
|
|
|
526
525
|
impl StartedActivityCancelEventRecorded {
|
|
527
526
|
pub(super) fn on_activity_task_completed(
|
|
528
527
|
self,
|
|
529
|
-
dat: SharedState,
|
|
528
|
+
dat: &mut SharedState,
|
|
530
529
|
attrs: ActivityTaskCompletedEventAttributes,
|
|
531
530
|
) -> ActivityMachineTransition<Completed> {
|
|
532
531
|
notify_if_not_already_cancelled(dat, |_| {
|
|
@@ -535,7 +534,7 @@ impl StartedActivityCancelEventRecorded {
|
|
|
535
534
|
}
|
|
536
535
|
pub(super) fn on_activity_task_failed(
|
|
537
536
|
self,
|
|
538
|
-
dat: SharedState,
|
|
537
|
+
dat: &mut SharedState,
|
|
539
538
|
attrs: ActivityTaskFailedEventAttributes,
|
|
540
539
|
) -> ActivityMachineTransition<Failed> {
|
|
541
540
|
notify_if_not_already_cancelled(dat, |dat| {
|
|
@@ -544,23 +543,23 @@ impl StartedActivityCancelEventRecorded {
|
|
|
544
543
|
}
|
|
545
544
|
pub(super) fn on_activity_task_timed_out(
|
|
546
545
|
self,
|
|
547
|
-
dat: SharedState,
|
|
546
|
+
dat: &mut SharedState,
|
|
548
547
|
attrs: ActivityTaskTimedOutEventAttributes,
|
|
549
548
|
) -> ActivityMachineTransition<TimedOut> {
|
|
550
549
|
notify_if_not_already_cancelled(dat, |dat| notify_lang_activity_timed_out(dat, attrs))
|
|
551
550
|
}
|
|
552
551
|
pub(super) fn on_activity_task_canceled(
|
|
553
552
|
self,
|
|
554
|
-
dat: SharedState,
|
|
553
|
+
dat: &mut SharedState,
|
|
555
554
|
attrs: ActivityTaskCanceledEventAttributes,
|
|
556
555
|
) -> ActivityMachineTransition<Canceled> {
|
|
557
|
-
notify_if_not_already_cancelled(dat, |
|
|
556
|
+
notify_if_not_already_cancelled(dat, |_| notify_lang_activity_cancelled(Some(attrs)))
|
|
558
557
|
}
|
|
559
558
|
}
|
|
560
559
|
|
|
561
560
|
fn notify_if_not_already_cancelled<S>(
|
|
562
|
-
dat: SharedState,
|
|
563
|
-
notifier: impl FnOnce(SharedState) -> ActivityMachineTransition<S>,
|
|
561
|
+
dat: &mut SharedState,
|
|
562
|
+
notifier: impl FnOnce(&mut SharedState) -> ActivityMachineTransition<S>,
|
|
564
563
|
) -> ActivityMachineTransition<S>
|
|
565
564
|
where
|
|
566
565
|
S: Into<ActivityMachineState> + Default,
|
|
@@ -639,7 +638,7 @@ pub(super) struct Canceled {}
|
|
|
639
638
|
impl Canceled {
|
|
640
639
|
pub(super) fn on_activity_task_started(
|
|
641
640
|
self,
|
|
642
|
-
dat: SharedState,
|
|
641
|
+
dat: &mut SharedState,
|
|
643
642
|
seq_num: i64,
|
|
644
643
|
) -> ActivityMachineTransition<Canceled> {
|
|
645
644
|
// Abandoned activities might start anyway. Ignore the result.
|
|
@@ -648,14 +647,13 @@ impl Canceled {
|
|
|
648
647
|
} else {
|
|
649
648
|
TransitionResult::Err(WFMachinesError::Nondeterminism(format!(
|
|
650
649
|
"Non-Abandon cancel mode activities cannot be started after being cancelled. \
|
|
651
|
-
Seq: {:?}"
|
|
652
|
-
seq_num
|
|
650
|
+
Seq: {seq_num:?}"
|
|
653
651
|
)))
|
|
654
652
|
}
|
|
655
653
|
}
|
|
656
654
|
pub(super) fn on_activity_task_completed(
|
|
657
655
|
self,
|
|
658
|
-
dat: SharedState,
|
|
656
|
+
dat: &mut SharedState,
|
|
659
657
|
attrs: ActivityTaskCompletedEventAttributes,
|
|
660
658
|
) -> ActivityMachineTransition<Canceled> {
|
|
661
659
|
// Abandoned activities might complete anyway. Ignore the result.
|
|
@@ -663,15 +661,14 @@ impl Canceled {
|
|
|
663
661
|
TransitionResult::default()
|
|
664
662
|
} else {
|
|
665
663
|
TransitionResult::Err(WFMachinesError::Nondeterminism(format!(
|
|
666
|
-
"Non-Abandon cancel mode activities cannot be completed after being cancelled: {:?}"
|
|
667
|
-
attrs
|
|
664
|
+
"Non-Abandon cancel mode activities cannot be completed after being cancelled: {attrs:?}"
|
|
668
665
|
)))
|
|
669
666
|
}
|
|
670
667
|
}
|
|
671
668
|
}
|
|
672
669
|
|
|
673
670
|
fn create_request_cancel_activity_task_command<S>(
|
|
674
|
-
dat: SharedState,
|
|
671
|
+
dat: &mut SharedState,
|
|
675
672
|
next_state: S,
|
|
676
673
|
) -> ActivityMachineTransition<S>
|
|
677
674
|
where
|
|
@@ -696,81 +693,102 @@ where
|
|
|
696
693
|
/// Notifies lang side that activity has timed out by sending a failure with timeout error as a cause.
|
|
697
694
|
/// State machine will transition into the TimedOut state.
|
|
698
695
|
fn notify_lang_activity_timed_out(
|
|
699
|
-
dat: SharedState,
|
|
696
|
+
dat: &SharedState,
|
|
700
697
|
attrs: ActivityTaskTimedOutEventAttributes,
|
|
701
698
|
) -> TransitionResult<ActivityMachine, TimedOut> {
|
|
702
|
-
ActivityMachineTransition::
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
))],
|
|
706
|
-
TimedOut::default(),
|
|
707
|
-
dat,
|
|
708
|
-
)
|
|
699
|
+
ActivityMachineTransition::commands(vec![ActivityMachineCommand::Fail(new_timeout_failure(
|
|
700
|
+
dat, attrs,
|
|
701
|
+
))])
|
|
709
702
|
}
|
|
710
703
|
|
|
711
|
-
///
|
|
712
|
-
/// as a cause. Optional cancelled_event, if passed, is used to supply event IDs.
|
|
713
|
-
/// transition into the `next_state` provided as a parameter.
|
|
704
|
+
/// Returns the transition to indicate activity has been cancelled by sending a failure with
|
|
705
|
+
/// cancelled failure as a cause. Optional cancelled_event, if passed, is used to supply event IDs.
|
|
714
706
|
fn notify_lang_activity_cancelled(
|
|
715
|
-
dat: SharedState,
|
|
716
707
|
canceled_event: Option<ActivityTaskCanceledEventAttributes>,
|
|
717
708
|
) -> ActivityMachineTransition<Canceled> {
|
|
718
|
-
ActivityMachineTransition::
|
|
719
|
-
vec![ActivityMachineCommand::Cancel(
|
|
720
|
-
canceled_event.and_then(|e| e.details),
|
|
721
|
-
)],
|
|
722
|
-
Canceled::default(),
|
|
723
|
-
dat,
|
|
724
|
-
)
|
|
709
|
+
ActivityMachineTransition::commands(vec![ActivityMachineCommand::Cancel(canceled_event)])
|
|
725
710
|
}
|
|
726
711
|
|
|
727
|
-
fn new_failure(dat: SharedState, attrs: ActivityTaskFailedEventAttributes) -> Failure {
|
|
712
|
+
fn new_failure(dat: &SharedState, attrs: ActivityTaskFailedEventAttributes) -> Failure {
|
|
713
|
+
let rs = attrs.retry_state();
|
|
728
714
|
Failure {
|
|
729
715
|
message: "Activity task failed".to_owned(),
|
|
730
716
|
cause: attrs.failure.map(Box::new),
|
|
731
|
-
failure_info: Some(
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
retry_state: attrs.retry_state,
|
|
739
|
-
started_event_id: attrs.started_event_id,
|
|
740
|
-
scheduled_event_id: attrs.scheduled_event_id,
|
|
741
|
-
},
|
|
717
|
+
failure_info: Some(activity_fail_info(
|
|
718
|
+
dat.attrs.activity_type.clone(),
|
|
719
|
+
dat.attrs.activity_id.clone(),
|
|
720
|
+
Some(attrs.identity),
|
|
721
|
+
rs,
|
|
722
|
+
attrs.started_event_id,
|
|
723
|
+
attrs.scheduled_event_id,
|
|
742
724
|
)),
|
|
743
725
|
..Default::default()
|
|
744
726
|
}
|
|
745
727
|
}
|
|
746
728
|
|
|
747
729
|
fn new_timeout_failure(dat: &SharedState, attrs: ActivityTaskTimedOutEventAttributes) -> Failure {
|
|
748
|
-
let
|
|
749
|
-
activity_id: dat.attrs.activity_id.to_string(),
|
|
750
|
-
activity_type: Some(ActivityType {
|
|
751
|
-
name: dat.attrs.activity_type.to_string(),
|
|
752
|
-
}),
|
|
753
|
-
scheduled_event_id: attrs.scheduled_event_id,
|
|
754
|
-
started_event_id: attrs.started_event_id,
|
|
755
|
-
retry_state: attrs.retry_state,
|
|
756
|
-
..Default::default()
|
|
757
|
-
};
|
|
730
|
+
let rs = attrs.retry_state();
|
|
758
731
|
Failure {
|
|
759
732
|
message: "Activity task timed out".to_string(),
|
|
760
733
|
cause: attrs.failure.map(Box::new),
|
|
761
|
-
failure_info: Some(
|
|
734
|
+
failure_info: Some(activity_fail_info(
|
|
735
|
+
dat.attrs.activity_type.clone(),
|
|
736
|
+
dat.attrs.activity_id.clone(),
|
|
737
|
+
None,
|
|
738
|
+
rs,
|
|
739
|
+
attrs.started_event_id,
|
|
740
|
+
attrs.scheduled_event_id,
|
|
741
|
+
)),
|
|
762
742
|
..Default::default()
|
|
763
743
|
}
|
|
764
744
|
}
|
|
765
745
|
|
|
746
|
+
fn new_cancel_failure(dat: &SharedState, attrs: ActivityTaskCanceledEventAttributes) -> Failure {
|
|
747
|
+
Failure {
|
|
748
|
+
message: "Activity cancelled".to_string(),
|
|
749
|
+
cause: Some(Box::from(Failure {
|
|
750
|
+
failure_info: Some(FailureInfo::CanceledFailureInfo(CanceledFailureInfo {
|
|
751
|
+
details: attrs.details.map(Into::into),
|
|
752
|
+
})),
|
|
753
|
+
..Default::default()
|
|
754
|
+
})),
|
|
755
|
+
failure_info: Some(activity_fail_info(
|
|
756
|
+
dat.attrs.activity_type.clone(),
|
|
757
|
+
dat.attrs.activity_id.clone(),
|
|
758
|
+
Some(attrs.identity),
|
|
759
|
+
RetryState::CancelRequested,
|
|
760
|
+
attrs.started_event_id,
|
|
761
|
+
attrs.scheduled_event_id,
|
|
762
|
+
)),
|
|
763
|
+
..Default::default()
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
pub fn activity_fail_info(
|
|
768
|
+
act_type: String,
|
|
769
|
+
act_id: String,
|
|
770
|
+
identity: Option<String>,
|
|
771
|
+
retry_state: RetryState,
|
|
772
|
+
started_event_id: i64,
|
|
773
|
+
scheduled_event_id: i64,
|
|
774
|
+
) -> FailureInfo {
|
|
775
|
+
FailureInfo::ActivityFailureInfo(ActivityFailureInfo {
|
|
776
|
+
identity: identity.unwrap_or_default(),
|
|
777
|
+
activity_type: Some(ActivityType { name: act_type }),
|
|
778
|
+
activity_id: act_id,
|
|
779
|
+
retry_state: retry_state as i32,
|
|
780
|
+
started_event_id,
|
|
781
|
+
scheduled_event_id,
|
|
782
|
+
})
|
|
783
|
+
}
|
|
784
|
+
|
|
766
785
|
fn convert_payloads(
|
|
767
786
|
event_info: Option<EventInfo>,
|
|
768
787
|
result: Option<Payloads>,
|
|
769
788
|
) -> Result<Option<Payload>, WFMachinesError> {
|
|
770
789
|
result.map(TryInto::try_into).transpose().map_err(|pe| {
|
|
771
790
|
WFMachinesError::Fatal(format!(
|
|
772
|
-
"Not exactly one payload in activity result ({}) for event: {:?}"
|
|
773
|
-
pe, event_info
|
|
791
|
+
"Not exactly one payload in activity result ({pe}) for event: {event_info:?}"
|
|
774
792
|
))
|
|
775
793
|
})
|
|
776
794
|
}
|
|
@@ -779,15 +797,17 @@ fn convert_payloads(
|
|
|
779
797
|
mod test {
|
|
780
798
|
use super::*;
|
|
781
799
|
use crate::{
|
|
782
|
-
replay::TestHistoryBuilder, test_help::canned_histories,
|
|
800
|
+
internal_flags::InternalFlags, replay::TestHistoryBuilder, test_help::canned_histories,
|
|
801
|
+
worker::workflow::ManagedWFFunc,
|
|
783
802
|
};
|
|
784
803
|
use rstest::{fixture, rstest};
|
|
785
|
-
use std::mem::discriminant;
|
|
804
|
+
use std::{cell::RefCell, mem::discriminant, rc::Rc};
|
|
786
805
|
use temporal_sdk::{
|
|
787
806
|
ActivityOptions, CancellableFuture, WfContext, WorkflowFunction, WorkflowResult,
|
|
788
807
|
};
|
|
789
|
-
use temporal_sdk_core_protos::
|
|
790
|
-
workflow_activation_job, WorkflowActivationJob,
|
|
808
|
+
use temporal_sdk_core_protos::{
|
|
809
|
+
coresdk::workflow_activation::{workflow_activation_job, WorkflowActivationJob},
|
|
810
|
+
DEFAULT_ACTIVITY_TYPE,
|
|
791
811
|
};
|
|
792
812
|
|
|
793
813
|
#[fixture]
|
|
@@ -807,7 +827,13 @@ mod test {
|
|
|
807
827
|
}
|
|
808
828
|
|
|
809
829
|
async fn activity_wf(command_sink: WfContext) -> WorkflowResult<()> {
|
|
810
|
-
command_sink
|
|
830
|
+
command_sink
|
|
831
|
+
.activity(ActivityOptions {
|
|
832
|
+
activity_id: Some("activity-id-1".to_string()),
|
|
833
|
+
activity_type: DEFAULT_ACTIVITY_TYPE.to_string(),
|
|
834
|
+
..Default::default()
|
|
835
|
+
})
|
|
836
|
+
.await;
|
|
811
837
|
Ok(().into())
|
|
812
838
|
}
|
|
813
839
|
|
|
@@ -895,13 +921,20 @@ mod test {
|
|
|
895
921
|
TimedOut {}.into(),
|
|
896
922
|
Completed {}.into(),
|
|
897
923
|
] {
|
|
898
|
-
let mut s = ActivityMachine
|
|
899
|
-
state
|
|
900
|
-
|
|
901
|
-
|
|
924
|
+
let mut s = ActivityMachine::from_parts(
|
|
925
|
+
state.clone(),
|
|
926
|
+
SharedState {
|
|
927
|
+
scheduled_event_id: 0,
|
|
928
|
+
started_event_id: 0,
|
|
929
|
+
attrs: Default::default(),
|
|
930
|
+
cancellation_type: Default::default(),
|
|
931
|
+
cancelled_before_sent: false,
|
|
932
|
+
internal_flags: Rc::new(RefCell::new(InternalFlags::new(&Default::default()))),
|
|
933
|
+
},
|
|
934
|
+
);
|
|
902
935
|
let cmds = s.cancel().unwrap();
|
|
903
936
|
assert_eq!(cmds.len(), 0);
|
|
904
|
-
assert_eq!(discriminant(&state), discriminant(
|
|
937
|
+
assert_eq!(discriminant(&state), discriminant(s.state()));
|
|
905
938
|
}
|
|
906
939
|
}
|
|
907
940
|
}
|