@temporalio/core-bridge 1.6.0 → 1.7.1
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 +520 -456
- package/lib/index.d.ts +8 -6
- package/lib/index.js.map +1 -1
- package/package.json +8 -3
- 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 +1 -1
- package/sdk-core/.github/workflows/heavy.yml +1 -0
- package/sdk-core/README.md +13 -7
- package/sdk-core/client/src/lib.rs +27 -9
- package/sdk-core/client/src/metrics.rs +17 -8
- package/sdk-core/client/src/raw.rs +3 -3
- package/sdk-core/core/Cargo.toml +3 -4
- package/sdk-core/core/src/abstractions/take_cell.rs +28 -0
- package/sdk-core/core/src/abstractions.rs +197 -18
- package/sdk-core/core/src/core_tests/activity_tasks.rs +137 -45
- package/sdk-core/core/src/core_tests/child_workflows.rs +6 -5
- package/sdk-core/core/src/core_tests/determinism.rs +212 -2
- package/sdk-core/core/src/core_tests/local_activities.rs +183 -36
- package/sdk-core/core/src/core_tests/queries.rs +32 -14
- package/sdk-core/core/src/core_tests/workers.rs +8 -5
- package/sdk-core/core/src/core_tests/workflow_tasks.rs +340 -51
- package/sdk-core/core/src/ephemeral_server/mod.rs +110 -8
- package/sdk-core/core/src/internal_flags.rs +141 -0
- package/sdk-core/core/src/lib.rs +14 -9
- package/sdk-core/core/src/replay/mod.rs +16 -27
- package/sdk-core/core/src/telemetry/metrics.rs +69 -35
- package/sdk-core/core/src/telemetry/mod.rs +38 -14
- package/sdk-core/core/src/telemetry/prometheus_server.rs +19 -13
- package/sdk-core/core/src/test_help/mod.rs +65 -13
- 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 +122 -6
- package/sdk-core/core/src/worker/activities.rs +347 -173
- 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 +137 -44
- package/sdk-core/core/src/worker/workflow/history_update.rs +132 -51
- package/sdk-core/core/src/worker/workflow/machines/activity_state_machine.rs +207 -166
- package/sdk-core/core/src/worker/workflow/machines/cancel_external_state_machine.rs +6 -7
- package/sdk-core/core/src/worker/workflow/machines/cancel_workflow_state_machine.rs +6 -7
- package/sdk-core/core/src/worker/workflow/machines/child_workflow_state_machine.rs +157 -82
- package/sdk-core/core/src/worker/workflow/machines/complete_workflow_state_machine.rs +12 -12
- package/sdk-core/core/src/worker/workflow/machines/continue_as_new_workflow_state_machine.rs +6 -7
- package/sdk-core/core/src/worker/workflow/machines/fail_workflow_state_machine.rs +13 -15
- package/sdk-core/core/src/worker/workflow/machines/local_activity_state_machine.rs +170 -60
- package/sdk-core/core/src/worker/workflow/machines/mod.rs +24 -16
- package/sdk-core/core/src/worker/workflow/machines/modify_workflow_properties_state_machine.rs +6 -8
- package/sdk-core/core/src/worker/workflow/machines/patch_state_machine.rs +320 -204
- package/sdk-core/core/src/worker/workflow/machines/signal_external_state_machine.rs +10 -13
- package/sdk-core/core/src/worker/workflow/machines/timer_state_machine.rs +15 -23
- package/sdk-core/core/src/worker/workflow/machines/upsert_search_attributes_state_machine.rs +187 -46
- package/sdk-core/core/src/worker/workflow/machines/workflow_machines.rs +237 -111
- package/sdk-core/core/src/worker/workflow/machines/workflow_task_state_machine.rs +13 -13
- package/sdk-core/core/src/worker/workflow/managed_run/managed_wf_test.rs +10 -6
- package/sdk-core/core/src/worker/workflow/managed_run.rs +81 -62
- package/sdk-core/core/src/worker/workflow/mod.rs +341 -79
- package/sdk-core/core/src/worker/workflow/run_cache.rs +18 -11
- package/sdk-core/core/src/worker/workflow/wft_extraction.rs +15 -3
- package/sdk-core/core/src/worker/workflow/workflow_stream/saved_wf_inputs.rs +2 -0
- package/sdk-core/core/src/worker/workflow/workflow_stream.rs +75 -52
- package/sdk-core/core-api/Cargo.toml +0 -1
- package/sdk-core/core-api/src/lib.rs +13 -7
- package/sdk-core/core-api/src/telemetry.rs +4 -6
- package/sdk-core/core-api/src/worker.rs +5 -0
- package/sdk-core/fsm/rustfsm_procmacro/src/lib.rs +80 -55
- package/sdk-core/fsm/rustfsm_trait/src/lib.rs +22 -68
- package/sdk-core/histories/ends_empty_wft_complete.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 +1 -1
- package/sdk-core/protos/api_upstream/temporal/api/command/v1/message.proto +5 -17
- package/sdk-core/protos/api_upstream/temporal/api/common/v1/message.proto +11 -0
- package/sdk-core/protos/api_upstream/temporal/api/enums/v1/command_type.proto +1 -6
- package/sdk-core/protos/api_upstream/temporal/api/enums/v1/event_type.proto +6 -6
- package/sdk-core/protos/api_upstream/temporal/api/enums/v1/failed_cause.proto +5 -0
- package/sdk-core/protos/api_upstream/temporal/api/enums/v1/update.proto +22 -6
- package/sdk-core/protos/api_upstream/temporal/api/history/v1/message.proto +48 -19
- package/sdk-core/protos/api_upstream/temporal/api/namespace/v1/message.proto +2 -0
- package/sdk-core/protos/api_upstream/temporal/api/operatorservice/v1/request_response.proto +3 -0
- package/sdk-core/protos/api_upstream/temporal/api/{enums/v1/interaction_type.proto → protocol/v1/message.proto} +29 -11
- package/sdk-core/protos/api_upstream/temporal/api/sdk/v1/task_complete_metadata.proto +63 -0
- package/sdk-core/protos/api_upstream/temporal/api/update/v1/message.proto +111 -0
- package/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +59 -28
- package/sdk-core/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +2 -2
- 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 +65 -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/sdk/Cargo.toml +1 -1
- package/sdk-core/sdk/src/lib.rs +21 -5
- 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 +9 -3
- package/sdk-core/sdk-core-protos/src/history_builder.rs +114 -89
- package/sdk-core/sdk-core-protos/src/history_info.rs +6 -1
- package/sdk-core/sdk-core-protos/src/lib.rs +205 -64
- package/sdk-core/test-utils/src/canned_histories.rs +106 -296
- package/sdk-core/test-utils/src/lib.rs +32 -5
- package/sdk-core/tests/heavy_tests.rs +10 -43
- package/sdk-core/tests/integ_tests/ephemeral_server_tests.rs +25 -3
- package/sdk-core/tests/integ_tests/heartbeat_tests.rs +5 -3
- package/sdk-core/tests/integ_tests/metrics_tests.rs +218 -16
- package/sdk-core/tests/integ_tests/polling_tests.rs +3 -8
- package/sdk-core/tests/integ_tests/queries_tests.rs +4 -2
- package/sdk-core/tests/integ_tests/visibility_tests.rs +34 -23
- package/sdk-core/tests/integ_tests/workflow_tests/activities.rs +97 -81
- package/sdk-core/tests/integ_tests/workflow_tests/cancel_external.rs +1 -0
- package/sdk-core/tests/integ_tests/workflow_tests/cancel_wf.rs +1 -0
- 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 +5 -1
- package/sdk-core/tests/integ_tests/workflow_tests/determinism.rs +1 -0
- package/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +25 -3
- package/sdk-core/tests/integ_tests/workflow_tests/modify_wf_properties.rs +2 -4
- package/sdk-core/tests/integ_tests/workflow_tests/patches.rs +30 -0
- package/sdk-core/tests/integ_tests/workflow_tests/replay.rs +64 -0
- package/sdk-core/tests/integ_tests/workflow_tests/resets.rs +1 -0
- package/sdk-core/tests/integ_tests/workflow_tests/signals.rs +4 -0
- package/sdk-core/tests/integ_tests/workflow_tests/stickyness.rs +3 -1
- package/sdk-core/tests/integ_tests/workflow_tests/timers.rs +7 -2
- package/sdk-core/tests/integ_tests/workflow_tests/upsert_search_attrs.rs +6 -7
- package/sdk-core/tests/integ_tests/workflow_tests.rs +8 -8
- package/sdk-core/tests/main.rs +16 -25
- package/sdk-core/tests/runner.rs +11 -9
- package/src/conversions.rs +14 -8
- package/src/runtime.rs +9 -8
- package/ts/index.ts +8 -6
- package/sdk-core/protos/api_upstream/temporal/api/interaction/v1/message.proto +0 -87
|
@@ -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(
|
|
@@ -263,10 +272,8 @@ impl WFMachinesAdapter for ActivityMachine {
|
|
|
263
272
|
ActivityMachineCommand::RequestCancellation(c) => {
|
|
264
273
|
self.machine_responses_from_cancel_request(c)
|
|
265
274
|
}
|
|
266
|
-
ActivityMachineCommand::Cancel(
|
|
267
|
-
vec![self
|
|
268
|
-
.create_cancelation_resolve(convert_payloads(event_info, details)?)
|
|
269
|
-
.into()]
|
|
275
|
+
ActivityMachineCommand::Cancel(attrs) => {
|
|
276
|
+
vec![self.create_cancelation_resolve(attrs).into()]
|
|
270
277
|
}
|
|
271
278
|
})
|
|
272
279
|
}
|
|
@@ -325,14 +332,7 @@ impl Cancellable for ActivityMachine {
|
|
|
325
332
|
self.machine_responses_from_cancel_request(cmd)
|
|
326
333
|
}
|
|
327
334
|
ActivityMachineCommand::Cancel(details) => {
|
|
328
|
-
vec![self
|
|
329
|
-
.create_cancelation_resolve(
|
|
330
|
-
details
|
|
331
|
-
.map(TryInto::try_into)
|
|
332
|
-
.transpose()
|
|
333
|
-
.unwrap_or_default(),
|
|
334
|
-
)
|
|
335
|
-
.into()]
|
|
335
|
+
vec![self.create_cancelation_resolve(details).into()]
|
|
336
336
|
}
|
|
337
337
|
x => panic!("Invalid cancel event response {x:?}"),
|
|
338
338
|
})
|
|
@@ -345,13 +345,14 @@ impl Cancellable for ActivityMachine {
|
|
|
345
345
|
}
|
|
346
346
|
}
|
|
347
347
|
|
|
348
|
-
#[derive(
|
|
348
|
+
#[derive(Clone)]
|
|
349
349
|
pub(super) struct SharedState {
|
|
350
350
|
scheduled_event_id: i64,
|
|
351
351
|
started_event_id: i64,
|
|
352
352
|
attrs: ScheduleActivity,
|
|
353
353
|
cancellation_type: ActivityCancellationType,
|
|
354
354
|
cancelled_before_sent: bool,
|
|
355
|
+
internal_flags: InternalFlagsRef,
|
|
355
356
|
}
|
|
356
357
|
|
|
357
358
|
#[derive(Default, Clone)]
|
|
@@ -370,28 +371,37 @@ pub(super) struct ScheduleCommandCreated {}
|
|
|
370
371
|
impl ScheduleCommandCreated {
|
|
371
372
|
pub(super) fn on_activity_task_scheduled(
|
|
372
373
|
self,
|
|
373
|
-
dat: SharedState,
|
|
374
|
-
|
|
374
|
+
dat: &mut SharedState,
|
|
375
|
+
sched_dat: ActTaskScheduledData,
|
|
375
376
|
) -> ActivityMachineTransition<ScheduledEventRecorded> {
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
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()
|
|
384
398
|
}
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
..dat
|
|
389
|
-
};
|
|
399
|
+
|
|
400
|
+
pub(super) fn on_canceled(self, dat: &mut SharedState) -> ActivityMachineTransition<Canceled> {
|
|
401
|
+
dat.cancelled_before_sent = true;
|
|
390
402
|
match dat.cancellation_type {
|
|
391
|
-
ActivityCancellationType::Abandon =>
|
|
392
|
-
|
|
393
|
-
}
|
|
394
|
-
_ => notify_lang_activity_cancelled(canceled_state, None),
|
|
403
|
+
ActivityCancellationType::Abandon => ActivityMachineTransition::default(),
|
|
404
|
+
_ => notify_lang_activity_cancelled(None),
|
|
395
405
|
}
|
|
396
406
|
}
|
|
397
407
|
}
|
|
@@ -402,21 +412,15 @@ pub(super) struct ScheduledEventRecorded {}
|
|
|
402
412
|
impl ScheduledEventRecorded {
|
|
403
413
|
pub(super) fn on_task_started(
|
|
404
414
|
self,
|
|
405
|
-
dat: SharedState,
|
|
415
|
+
dat: &mut SharedState,
|
|
406
416
|
started_event_id: i64,
|
|
407
417
|
) -> ActivityMachineTransition<Started> {
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
Started::default(),
|
|
411
|
-
SharedState {
|
|
412
|
-
started_event_id,
|
|
413
|
-
..dat
|
|
414
|
-
},
|
|
415
|
-
)
|
|
418
|
+
dat.started_event_id = started_event_id;
|
|
419
|
+
ActivityMachineTransition::default()
|
|
416
420
|
}
|
|
417
421
|
pub(super) fn on_task_timed_out(
|
|
418
422
|
self,
|
|
419
|
-
dat: SharedState,
|
|
423
|
+
dat: &mut SharedState,
|
|
420
424
|
attrs: ActivityTaskTimedOutEventAttributes,
|
|
421
425
|
) -> ActivityMachineTransition<TimedOut> {
|
|
422
426
|
notify_lang_activity_timed_out(dat, attrs)
|
|
@@ -424,15 +428,15 @@ impl ScheduledEventRecorded {
|
|
|
424
428
|
|
|
425
429
|
pub(super) fn on_canceled(
|
|
426
430
|
self,
|
|
427
|
-
dat: SharedState,
|
|
431
|
+
dat: &mut SharedState,
|
|
428
432
|
) -> ActivityMachineTransition<ScheduledActivityCancelCommandCreated> {
|
|
429
433
|
create_request_cancel_activity_task_command(
|
|
430
434
|
dat,
|
|
431
435
|
ScheduledActivityCancelCommandCreated::default(),
|
|
432
436
|
)
|
|
433
437
|
}
|
|
434
|
-
pub(super) fn on_abandoned(self
|
|
435
|
-
notify_lang_activity_cancelled(
|
|
438
|
+
pub(super) fn on_abandoned(self) -> ActivityMachineTransition<Canceled> {
|
|
439
|
+
notify_lang_activity_cancelled(None)
|
|
436
440
|
}
|
|
437
441
|
}
|
|
438
442
|
|
|
@@ -451,7 +455,7 @@ impl Started {
|
|
|
451
455
|
}
|
|
452
456
|
pub(super) fn on_activity_task_failed(
|
|
453
457
|
self,
|
|
454
|
-
dat: SharedState,
|
|
458
|
+
dat: &mut SharedState,
|
|
455
459
|
attrs: ActivityTaskFailedEventAttributes,
|
|
456
460
|
) -> ActivityMachineTransition<Failed> {
|
|
457
461
|
ActivityMachineTransition::ok(
|
|
@@ -462,7 +466,7 @@ impl Started {
|
|
|
462
466
|
|
|
463
467
|
pub(super) fn on_activity_task_timed_out(
|
|
464
468
|
self,
|
|
465
|
-
dat: SharedState,
|
|
469
|
+
dat: &mut SharedState,
|
|
466
470
|
attrs: ActivityTaskTimedOutEventAttributes,
|
|
467
471
|
) -> ActivityMachineTransition<TimedOut> {
|
|
468
472
|
notify_lang_activity_timed_out(dat, attrs)
|
|
@@ -470,15 +474,15 @@ impl Started {
|
|
|
470
474
|
|
|
471
475
|
pub(super) fn on_canceled(
|
|
472
476
|
self,
|
|
473
|
-
dat: SharedState,
|
|
477
|
+
dat: &mut SharedState,
|
|
474
478
|
) -> ActivityMachineTransition<StartedActivityCancelCommandCreated> {
|
|
475
479
|
create_request_cancel_activity_task_command(
|
|
476
480
|
dat,
|
|
477
481
|
StartedActivityCancelCommandCreated::default(),
|
|
478
482
|
)
|
|
479
483
|
}
|
|
480
|
-
pub(super) fn on_abandoned(self
|
|
481
|
-
notify_lang_activity_cancelled(
|
|
484
|
+
pub(super) fn on_abandoned(self) -> ActivityMachineTransition<Canceled> {
|
|
485
|
+
notify_lang_activity_cancelled(None)
|
|
482
486
|
}
|
|
483
487
|
}
|
|
484
488
|
|
|
@@ -491,15 +495,15 @@ pub(super) struct ScheduledActivityCancelEventRecorded {}
|
|
|
491
495
|
impl ScheduledActivityCancelEventRecorded {
|
|
492
496
|
pub(super) fn on_activity_task_canceled(
|
|
493
497
|
self,
|
|
494
|
-
dat: SharedState,
|
|
498
|
+
dat: &mut SharedState,
|
|
495
499
|
attrs: ActivityTaskCanceledEventAttributes,
|
|
496
500
|
) -> ActivityMachineTransition<Canceled> {
|
|
497
|
-
notify_if_not_already_cancelled(dat, |
|
|
501
|
+
notify_if_not_already_cancelled(dat, |_| notify_lang_activity_cancelled(Some(attrs)))
|
|
498
502
|
}
|
|
499
503
|
|
|
500
504
|
pub(super) fn on_activity_task_timed_out(
|
|
501
505
|
self,
|
|
502
|
-
dat: SharedState,
|
|
506
|
+
dat: &mut SharedState,
|
|
503
507
|
attrs: ActivityTaskTimedOutEventAttributes,
|
|
504
508
|
) -> ActivityMachineTransition<TimedOut> {
|
|
505
509
|
notify_if_not_already_cancelled(dat, |dat| notify_lang_activity_timed_out(dat, attrs))
|
|
@@ -521,7 +525,7 @@ pub(super) struct StartedActivityCancelEventRecorded {}
|
|
|
521
525
|
impl StartedActivityCancelEventRecorded {
|
|
522
526
|
pub(super) fn on_activity_task_completed(
|
|
523
527
|
self,
|
|
524
|
-
dat: SharedState,
|
|
528
|
+
dat: &mut SharedState,
|
|
525
529
|
attrs: ActivityTaskCompletedEventAttributes,
|
|
526
530
|
) -> ActivityMachineTransition<Completed> {
|
|
527
531
|
notify_if_not_already_cancelled(dat, |_| {
|
|
@@ -530,7 +534,7 @@ impl StartedActivityCancelEventRecorded {
|
|
|
530
534
|
}
|
|
531
535
|
pub(super) fn on_activity_task_failed(
|
|
532
536
|
self,
|
|
533
|
-
dat: SharedState,
|
|
537
|
+
dat: &mut SharedState,
|
|
534
538
|
attrs: ActivityTaskFailedEventAttributes,
|
|
535
539
|
) -> ActivityMachineTransition<Failed> {
|
|
536
540
|
notify_if_not_already_cancelled(dat, |dat| {
|
|
@@ -539,23 +543,23 @@ impl StartedActivityCancelEventRecorded {
|
|
|
539
543
|
}
|
|
540
544
|
pub(super) fn on_activity_task_timed_out(
|
|
541
545
|
self,
|
|
542
|
-
dat: SharedState,
|
|
546
|
+
dat: &mut SharedState,
|
|
543
547
|
attrs: ActivityTaskTimedOutEventAttributes,
|
|
544
548
|
) -> ActivityMachineTransition<TimedOut> {
|
|
545
549
|
notify_if_not_already_cancelled(dat, |dat| notify_lang_activity_timed_out(dat, attrs))
|
|
546
550
|
}
|
|
547
551
|
pub(super) fn on_activity_task_canceled(
|
|
548
552
|
self,
|
|
549
|
-
dat: SharedState,
|
|
553
|
+
dat: &mut SharedState,
|
|
550
554
|
attrs: ActivityTaskCanceledEventAttributes,
|
|
551
555
|
) -> ActivityMachineTransition<Canceled> {
|
|
552
|
-
notify_if_not_already_cancelled(dat, |
|
|
556
|
+
notify_if_not_already_cancelled(dat, |_| notify_lang_activity_cancelled(Some(attrs)))
|
|
553
557
|
}
|
|
554
558
|
}
|
|
555
559
|
|
|
556
560
|
fn notify_if_not_already_cancelled<S>(
|
|
557
|
-
dat: SharedState,
|
|
558
|
-
notifier: impl FnOnce(SharedState) -> ActivityMachineTransition<S>,
|
|
561
|
+
dat: &mut SharedState,
|
|
562
|
+
notifier: impl FnOnce(&mut SharedState) -> ActivityMachineTransition<S>,
|
|
559
563
|
) -> ActivityMachineTransition<S>
|
|
560
564
|
where
|
|
561
565
|
S: Into<ActivityMachineState> + Default,
|
|
@@ -634,7 +638,7 @@ pub(super) struct Canceled {}
|
|
|
634
638
|
impl Canceled {
|
|
635
639
|
pub(super) fn on_activity_task_started(
|
|
636
640
|
self,
|
|
637
|
-
dat: SharedState,
|
|
641
|
+
dat: &mut SharedState,
|
|
638
642
|
seq_num: i64,
|
|
639
643
|
) -> ActivityMachineTransition<Canceled> {
|
|
640
644
|
// Abandoned activities might start anyway. Ignore the result.
|
|
@@ -649,7 +653,7 @@ impl Canceled {
|
|
|
649
653
|
}
|
|
650
654
|
pub(super) fn on_activity_task_completed(
|
|
651
655
|
self,
|
|
652
|
-
dat: SharedState,
|
|
656
|
+
dat: &mut SharedState,
|
|
653
657
|
attrs: ActivityTaskCompletedEventAttributes,
|
|
654
658
|
) -> ActivityMachineTransition<Canceled> {
|
|
655
659
|
// Abandoned activities might complete anyway. Ignore the result.
|
|
@@ -664,7 +668,7 @@ impl Canceled {
|
|
|
664
668
|
}
|
|
665
669
|
|
|
666
670
|
fn create_request_cancel_activity_task_command<S>(
|
|
667
|
-
dat: SharedState,
|
|
671
|
+
dat: &mut SharedState,
|
|
668
672
|
next_state: S,
|
|
669
673
|
) -> ActivityMachineTransition<S>
|
|
670
674
|
where
|
|
@@ -689,73 +693,95 @@ where
|
|
|
689
693
|
/// Notifies lang side that activity has timed out by sending a failure with timeout error as a cause.
|
|
690
694
|
/// State machine will transition into the TimedOut state.
|
|
691
695
|
fn notify_lang_activity_timed_out(
|
|
692
|
-
dat: SharedState,
|
|
696
|
+
dat: &SharedState,
|
|
693
697
|
attrs: ActivityTaskTimedOutEventAttributes,
|
|
694
698
|
) -> TransitionResult<ActivityMachine, TimedOut> {
|
|
695
|
-
ActivityMachineTransition::
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
))],
|
|
699
|
-
TimedOut::default(),
|
|
700
|
-
dat,
|
|
701
|
-
)
|
|
699
|
+
ActivityMachineTransition::commands(vec![ActivityMachineCommand::Fail(new_timeout_failure(
|
|
700
|
+
dat, attrs,
|
|
701
|
+
))])
|
|
702
702
|
}
|
|
703
703
|
|
|
704
|
-
///
|
|
705
|
-
/// as a cause. Optional cancelled_event, if passed, is used to supply event IDs.
|
|
706
|
-
/// 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.
|
|
707
706
|
fn notify_lang_activity_cancelled(
|
|
708
|
-
dat: SharedState,
|
|
709
707
|
canceled_event: Option<ActivityTaskCanceledEventAttributes>,
|
|
710
708
|
) -> ActivityMachineTransition<Canceled> {
|
|
711
|
-
ActivityMachineTransition::
|
|
712
|
-
vec![ActivityMachineCommand::Cancel(
|
|
713
|
-
canceled_event.and_then(|e| e.details),
|
|
714
|
-
)],
|
|
715
|
-
Canceled::default(),
|
|
716
|
-
dat,
|
|
717
|
-
)
|
|
709
|
+
ActivityMachineTransition::commands(vec![ActivityMachineCommand::Cancel(canceled_event)])
|
|
718
710
|
}
|
|
719
711
|
|
|
720
|
-
fn new_failure(dat: SharedState, attrs: ActivityTaskFailedEventAttributes) -> Failure {
|
|
712
|
+
fn new_failure(dat: &SharedState, attrs: ActivityTaskFailedEventAttributes) -> Failure {
|
|
713
|
+
let rs = attrs.retry_state();
|
|
721
714
|
Failure {
|
|
722
715
|
message: "Activity task failed".to_owned(),
|
|
723
716
|
cause: attrs.failure.map(Box::new),
|
|
724
|
-
failure_info: Some(
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
retry_state: attrs.retry_state,
|
|
732
|
-
started_event_id: attrs.started_event_id,
|
|
733
|
-
scheduled_event_id: attrs.scheduled_event_id,
|
|
734
|
-
},
|
|
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,
|
|
735
724
|
)),
|
|
736
725
|
..Default::default()
|
|
737
726
|
}
|
|
738
727
|
}
|
|
739
728
|
|
|
740
729
|
fn new_timeout_failure(dat: &SharedState, attrs: ActivityTaskTimedOutEventAttributes) -> Failure {
|
|
741
|
-
let
|
|
742
|
-
activity_id: dat.attrs.activity_id.to_string(),
|
|
743
|
-
activity_type: Some(ActivityType {
|
|
744
|
-
name: dat.attrs.activity_type.to_string(),
|
|
745
|
-
}),
|
|
746
|
-
scheduled_event_id: attrs.scheduled_event_id,
|
|
747
|
-
started_event_id: attrs.started_event_id,
|
|
748
|
-
retry_state: attrs.retry_state,
|
|
749
|
-
..Default::default()
|
|
750
|
-
};
|
|
730
|
+
let rs = attrs.retry_state();
|
|
751
731
|
Failure {
|
|
752
732
|
message: "Activity task timed out".to_string(),
|
|
753
733
|
cause: attrs.failure.map(Box::new),
|
|
754
|
-
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
|
+
)),
|
|
755
742
|
..Default::default()
|
|
756
743
|
}
|
|
757
744
|
}
|
|
758
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
|
+
|
|
759
785
|
fn convert_payloads(
|
|
760
786
|
event_info: Option<EventInfo>,
|
|
761
787
|
result: Option<Payloads>,
|
|
@@ -771,15 +797,17 @@ fn convert_payloads(
|
|
|
771
797
|
mod test {
|
|
772
798
|
use super::*;
|
|
773
799
|
use crate::{
|
|
774
|
-
replay::TestHistoryBuilder, test_help::canned_histories,
|
|
800
|
+
internal_flags::InternalFlags, replay::TestHistoryBuilder, test_help::canned_histories,
|
|
801
|
+
worker::workflow::ManagedWFFunc,
|
|
775
802
|
};
|
|
776
803
|
use rstest::{fixture, rstest};
|
|
777
|
-
use std::mem::discriminant;
|
|
804
|
+
use std::{cell::RefCell, mem::discriminant, rc::Rc};
|
|
778
805
|
use temporal_sdk::{
|
|
779
806
|
ActivityOptions, CancellableFuture, WfContext, WorkflowFunction, WorkflowResult,
|
|
780
807
|
};
|
|
781
|
-
use temporal_sdk_core_protos::
|
|
782
|
-
workflow_activation_job, WorkflowActivationJob,
|
|
808
|
+
use temporal_sdk_core_protos::{
|
|
809
|
+
coresdk::workflow_activation::{workflow_activation_job, WorkflowActivationJob},
|
|
810
|
+
DEFAULT_ACTIVITY_TYPE,
|
|
783
811
|
};
|
|
784
812
|
|
|
785
813
|
#[fixture]
|
|
@@ -799,7 +827,13 @@ mod test {
|
|
|
799
827
|
}
|
|
800
828
|
|
|
801
829
|
async fn activity_wf(command_sink: WfContext) -> WorkflowResult<()> {
|
|
802
|
-
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;
|
|
803
837
|
Ok(().into())
|
|
804
838
|
}
|
|
805
839
|
|
|
@@ -887,13 +921,20 @@ mod test {
|
|
|
887
921
|
TimedOut {}.into(),
|
|
888
922
|
Completed {}.into(),
|
|
889
923
|
] {
|
|
890
|
-
let mut s = ActivityMachine
|
|
891
|
-
state
|
|
892
|
-
|
|
893
|
-
|
|
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
|
+
);
|
|
894
935
|
let cmds = s.cancel().unwrap();
|
|
895
936
|
assert_eq!(cmds.len(), 0);
|
|
896
|
-
assert_eq!(discriminant(&state), discriminant(
|
|
937
|
+
assert_eq!(discriminant(&state), discriminant(s.state()));
|
|
897
938
|
}
|
|
898
939
|
}
|
|
899
940
|
}
|