@temporalio/core-bridge 1.11.7 → 1.11.8
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 +504 -341
- package/package.json +3 -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/.cargo/config.toml +5 -0
- package/sdk-core/.github/workflows/per-pr.yml +59 -5
- package/sdk-core/Cargo.toml +3 -2
- package/sdk-core/client/Cargo.toml +3 -3
- package/sdk-core/client/src/lib.rs +154 -161
- package/sdk-core/client/src/metrics.rs +15 -8
- package/sdk-core/client/src/proxy.rs +1 -1
- package/sdk-core/client/src/raw.rs +176 -33
- package/sdk-core/client/src/retry.rs +102 -465
- package/sdk-core/client/src/worker_registry/mod.rs +2 -2
- package/sdk-core/client/src/workflow_handle/mod.rs +19 -1
- package/sdk-core/core/Cargo.toml +12 -14
- package/sdk-core/core/benches/workflow_replay.rs +1 -1
- package/sdk-core/core/src/abstractions.rs +2 -2
- package/sdk-core/core/src/core_tests/activity_tasks.rs +99 -46
- package/sdk-core/core/src/core_tests/child_workflows.rs +68 -9
- package/sdk-core/core/src/core_tests/determinism.rs +2 -2
- package/sdk-core/core/src/core_tests/local_activities.rs +20 -33
- package/sdk-core/core/src/core_tests/mod.rs +7 -8
- package/sdk-core/core/src/core_tests/queries.rs +79 -79
- package/sdk-core/core/src/core_tests/replay_flag.rs +5 -5
- package/sdk-core/core/src/core_tests/updates.rs +6 -6
- package/sdk-core/core/src/core_tests/workers.rs +19 -22
- package/sdk-core/core/src/core_tests/workflow_cancels.rs +3 -3
- package/sdk-core/core/src/core_tests/workflow_tasks.rs +154 -106
- package/sdk-core/core/src/ephemeral_server/mod.rs +66 -10
- package/sdk-core/core/src/internal_flags.rs +103 -12
- package/sdk-core/core/src/lib.rs +21 -13
- package/sdk-core/core/src/pollers/mod.rs +200 -6
- package/sdk-core/core/src/pollers/poll_buffer.rs +32 -8
- package/sdk-core/core/src/protosext/mod.rs +7 -7
- package/sdk-core/core/src/protosext/protocol_messages.rs +2 -2
- package/sdk-core/core/src/replay/mod.rs +8 -9
- package/sdk-core/core/src/retry_logic.rs +8 -6
- package/sdk-core/core/src/telemetry/log_export.rs +4 -4
- package/sdk-core/core/src/telemetry/metrics.rs +111 -25
- package/sdk-core/core/src/telemetry/mod.rs +11 -4
- package/sdk-core/core/src/telemetry/otel.rs +108 -144
- package/sdk-core/core/src/telemetry/prometheus_server.rs +1 -4
- package/sdk-core/core/src/test_help/mod.rs +27 -21
- package/sdk-core/core/src/worker/activities/activity_heartbeat_manager.rs +7 -5
- package/sdk-core/core/src/worker/activities/local_activities.rs +9 -9
- package/sdk-core/core/src/worker/activities.rs +34 -46
- package/sdk-core/core/src/worker/client/mocks.rs +24 -2
- package/sdk-core/core/src/worker/client.rs +169 -33
- package/sdk-core/core/src/worker/mod.rs +132 -56
- package/sdk-core/core/src/worker/nexus.rs +410 -0
- package/sdk-core/core/src/worker/tuner/resource_based.rs +27 -5
- package/sdk-core/core/src/worker/tuner.rs +29 -2
- package/sdk-core/core/src/worker/workflow/driven_workflow.rs +8 -3
- package/sdk-core/core/src/worker/workflow/history_update.rs +5 -8
- package/sdk-core/core/src/worker/workflow/machines/activity_state_machine.rs +83 -87
- package/sdk-core/core/src/worker/workflow/machines/cancel_external_state_machine.rs +38 -38
- package/sdk-core/core/src/worker/workflow/machines/cancel_nexus_op_state_machine.rs +117 -0
- package/sdk-core/core/src/worker/workflow/machines/cancel_workflow_state_machine.rs +8 -18
- package/sdk-core/core/src/worker/workflow/machines/child_workflow_state_machine.rs +114 -108
- package/sdk-core/core/src/worker/workflow/machines/complete_workflow_state_machine.rs +16 -31
- package/sdk-core/core/src/worker/workflow/machines/continue_as_new_workflow_state_machine.rs +7 -14
- package/sdk-core/core/src/worker/workflow/machines/fail_workflow_state_machine.rs +8 -15
- package/sdk-core/core/src/worker/workflow/machines/local_activity_state_machine.rs +34 -75
- package/sdk-core/core/src/worker/workflow/machines/mod.rs +26 -48
- package/sdk-core/core/src/worker/workflow/machines/modify_workflow_properties_state_machine.rs +10 -17
- package/sdk-core/core/src/worker/workflow/machines/nexus_operation_state_machine.rs +543 -0
- package/sdk-core/core/src/worker/workflow/machines/patch_state_machine.rs +22 -31
- package/sdk-core/core/src/worker/workflow/machines/signal_external_state_machine.rs +53 -51
- package/sdk-core/core/src/worker/workflow/machines/timer_state_machine.rs +40 -45
- package/sdk-core/core/src/worker/workflow/machines/transition_coverage.rs +2 -2
- package/sdk-core/core/src/worker/workflow/machines/update_state_machine.rs +8 -10
- package/sdk-core/core/src/worker/workflow/machines/upsert_search_attributes_state_machine.rs +24 -30
- package/sdk-core/core/src/worker/workflow/machines/workflow_machines.rs +182 -116
- package/sdk-core/core/src/worker/workflow/machines/workflow_task_state_machine.rs +4 -8
- package/sdk-core/core/src/worker/workflow/managed_run.rs +75 -45
- package/sdk-core/core/src/worker/workflow/mod.rs +104 -55
- package/sdk-core/core/src/worker/workflow/run_cache.rs +23 -4
- package/sdk-core/core/src/worker/workflow/wft_extraction.rs +4 -4
- package/sdk-core/core/src/worker/workflow/wft_poller.rs +3 -3
- package/sdk-core/core/src/worker/workflow/workflow_stream.rs +32 -13
- package/sdk-core/core-api/Cargo.toml +2 -3
- package/sdk-core/core-api/src/errors.rs +22 -20
- package/sdk-core/core-api/src/lib.rs +24 -5
- package/sdk-core/core-api/src/telemetry/metrics.rs +27 -1
- package/sdk-core/core-api/src/telemetry.rs +37 -3
- package/sdk-core/core-api/src/worker.rs +36 -3
- package/sdk-core/docker/docker-compose-ci.yaml +25 -0
- package/sdk-core/etc/otel-collector-ci.yaml +36 -0
- package/sdk-core/etc/otel-collector-config.yaml +3 -3
- package/sdk-core/etc/prometheus.yaml +1 -1
- package/sdk-core/fsm/Cargo.toml +1 -1
- package/sdk-core/fsm/rustfsm_procmacro/Cargo.toml +1 -1
- package/sdk-core/fsm/rustfsm_procmacro/src/lib.rs +3 -4
- package/sdk-core/fsm/rustfsm_procmacro/tests/trybuild/no_handle_conversions_require_into_fail.stderr +1 -1
- package/sdk-core/fsm/rustfsm_trait/Cargo.toml +1 -1
- package/sdk-core/sdk/Cargo.toml +1 -2
- package/sdk-core/sdk/src/activity_context.rs +1 -1
- package/sdk-core/sdk/src/interceptors.rs +1 -1
- package/sdk-core/sdk/src/lib.rs +126 -54
- package/sdk-core/sdk/src/workflow_context/options.rs +184 -74
- package/sdk-core/sdk/src/workflow_context.rs +193 -79
- package/sdk-core/sdk/src/workflow_future.rs +151 -131
- package/sdk-core/sdk-core-protos/Cargo.toml +3 -4
- package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/VERSION +1 -1
- package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/temporal/api/cloud/account/v1/message.proto +46 -0
- package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/temporal/api/cloud/cloudservice/v1/request_response.proto +254 -5
- package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/temporal/api/cloud/cloudservice/v1/service.proto +108 -2
- package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/temporal/api/cloud/identity/v1/message.proto +94 -15
- package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/temporal/api/cloud/namespace/v1/message.proto +102 -4
- package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/temporal/api/cloud/nexus/v1/message.proto +84 -0
- package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/temporal/api/cloud/operation/v1/message.proto +25 -10
- package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/temporal/api/cloud/region/v1/message.proto +14 -1
- package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/temporal/api/cloud/resource/v1/message.proto +25 -0
- package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/temporal/api/cloud/sink/v1/message.proto +41 -0
- package/sdk-core/sdk-core-protos/protos/api_cloud_upstream/temporal/api/cloud/usage/v1/message.proto +59 -0
- package/sdk-core/sdk-core-protos/protos/api_upstream/.github/PULL_REQUEST_TEMPLATE.md +2 -0
- package/sdk-core/sdk-core-protos/protos/api_upstream/.github/workflows/create-release.yml +135 -0
- package/sdk-core/sdk-core-protos/protos/api_upstream/.github/workflows/push-to-buf.yml +20 -0
- package/sdk-core/sdk-core-protos/protos/api_upstream/.github/workflows/trigger-api-go-delete-release.yml +13 -0
- package/sdk-core/sdk-core-protos/protos/api_upstream/.github/workflows/trigger-api-go-publish-release.yml +13 -0
- package/sdk-core/sdk-core-protos/protos/api_upstream/.github/workflows/trigger-api-go-update.yml +13 -21
- package/sdk-core/sdk-core-protos/protos/api_upstream/Makefile +2 -2
- package/sdk-core/sdk-core-protos/protos/api_upstream/buf.yaml +1 -0
- package/sdk-core/sdk-core-protos/protos/api_upstream/openapi/openapiv2.json +3386 -1047
- package/sdk-core/sdk-core-protos/protos/api_upstream/openapi/openapiv3.yaml +3529 -1144
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/batch/v1/message.proto +39 -1
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/command/v1/message.proto +6 -0
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/common/v1/message.proto +39 -1
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/deployment/v1/message.proto +252 -0
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/batch_operation.proto +1 -0
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/common.proto +6 -0
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/deployment.proto +96 -0
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/event_type.proto +2 -0
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/failed_cause.proto +2 -0
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/nexus.proto +42 -0
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/reset.proto +2 -0
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/enums/v1/workflow.proto +43 -2
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/errordetails/v1/message.proto +13 -1
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/failure/v1/message.proto +14 -0
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/history/v1/message.proto +70 -12
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/nexus/v1/message.proto +12 -0
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/query/v1/message.proto +9 -2
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/taskqueue/v1/message.proto +46 -2
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/workflow/v1/message.proto +206 -0
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/workflowservice/v1/request_response.proto +482 -97
- package/sdk-core/sdk-core-protos/protos/api_upstream/temporal/api/workflowservice/v1/service.proto +230 -43
- package/sdk-core/sdk-core-protos/protos/local/temporal/sdk/core/core_interface.proto +6 -0
- package/sdk-core/sdk-core-protos/protos/local/temporal/sdk/core/nexus/nexus.proto +71 -0
- package/sdk-core/sdk-core-protos/protos/local/temporal/sdk/core/workflow_activation/workflow_activation.proto +46 -2
- package/sdk-core/sdk-core-protos/protos/local/temporal/sdk/core/workflow_commands/workflow_commands.proto +55 -9
- package/sdk-core/sdk-core-protos/src/history_builder.rs +5 -5
- package/sdk-core/sdk-core-protos/src/history_info.rs +5 -6
- package/sdk-core/sdk-core-protos/src/lib.rs +414 -34
- package/sdk-core/sdk-core-protos/src/task_token.rs +1 -1
- package/sdk-core/test-utils/Cargo.toml +3 -11
- package/sdk-core/test-utils/src/canned_histories.rs +1 -1
- package/sdk-core/test-utils/src/lib.rs +159 -85
- package/sdk-core/tests/fuzzy_workflow.rs +3 -3
- package/sdk-core/tests/heavy_tests.rs +3 -3
- package/sdk-core/tests/integ_tests/client_tests.rs +171 -20
- package/sdk-core/tests/integ_tests/ephemeral_server_tests.rs +45 -39
- package/sdk-core/tests/integ_tests/heartbeat_tests.rs +7 -6
- package/sdk-core/tests/integ_tests/metrics_tests.rs +492 -35
- package/sdk-core/tests/integ_tests/polling_tests.rs +7 -5
- package/sdk-core/tests/integ_tests/queries_tests.rs +14 -17
- package/sdk-core/tests/integ_tests/update_tests.rs +47 -44
- package/sdk-core/tests/integ_tests/visibility_tests.rs +4 -3
- package/sdk-core/tests/integ_tests/worker_tests.rs +5 -5
- package/sdk-core/tests/integ_tests/workflow_tests/activities.rs +15 -13
- package/sdk-core/tests/integ_tests/workflow_tests/cancel_external.rs +28 -14
- package/sdk-core/tests/integ_tests/workflow_tests/cancel_wf.rs +7 -1
- package/sdk-core/tests/integ_tests/workflow_tests/child_workflows.rs +57 -4
- package/sdk-core/tests/integ_tests/workflow_tests/eager.rs +1 -1
- package/sdk-core/tests/integ_tests/workflow_tests/local_activities.rs +24 -18
- package/sdk-core/tests/integ_tests/workflow_tests/nexus.rs +506 -0
- package/sdk-core/tests/integ_tests/workflow_tests/patches.rs +1 -1
- package/sdk-core/tests/integ_tests/workflow_tests/priority.rs +104 -0
- package/sdk-core/tests/integ_tests/workflow_tests/replay.rs +34 -31
- package/sdk-core/tests/integ_tests/workflow_tests/resets.rs +1 -1
- package/sdk-core/tests/integ_tests/workflow_tests/timers.rs +10 -7
- package/sdk-core/tests/integ_tests/workflow_tests.rs +152 -116
- package/sdk-core/tests/main.rs +36 -6
- package/sdk-core/tests/runner.rs +30 -9
- package/src/conversions/slot_supplier_bridge.rs +4 -0
- package/src/conversions.rs +1 -0
- package/src/worker.rs +5 -7
- package/sdk-core/core/src/worker/activities/activity_task_poller_stream.rs +0 -78
|
@@ -1,34 +1,33 @@
|
|
|
1
1
|
#![allow(clippy::large_enum_variant)]
|
|
2
2
|
|
|
3
3
|
use super::{
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
EventInfo, NewMachineWithCommand, OnEventWrapper, WFMachinesAdapter, WFMachinesError,
|
|
5
|
+
workflow_machines::MachineResponse,
|
|
6
6
|
};
|
|
7
7
|
use crate::{
|
|
8
8
|
abstractions::dbg_panic,
|
|
9
9
|
internal_flags::CoreInternalFlags,
|
|
10
|
-
worker::workflow::{machines::HistEventData
|
|
10
|
+
worker::workflow::{InternalFlagsRef, machines::HistEventData},
|
|
11
11
|
};
|
|
12
|
-
use rustfsm::{
|
|
12
|
+
use rustfsm::{MachineError, StateMachine, TransitionResult, fsm};
|
|
13
13
|
use std::convert::{TryFrom, TryInto};
|
|
14
14
|
use temporal_sdk_core_protos::{
|
|
15
15
|
coresdk::{
|
|
16
|
-
activity_result::{self as ar,
|
|
16
|
+
activity_result::{self as ar, ActivityResolution, Cancellation, activity_resolution},
|
|
17
17
|
workflow_activation::ResolveActivity,
|
|
18
18
|
workflow_commands::{ActivityCancellationType, ScheduleActivity},
|
|
19
19
|
},
|
|
20
20
|
temporal::api::{
|
|
21
21
|
command::v1::{
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
Command, RequestCancelActivityTaskCommandAttributes, command,
|
|
23
|
+
schedule_activity_cmd_to_api,
|
|
24
24
|
},
|
|
25
25
|
common::v1::{ActivityType, Payload, Payloads},
|
|
26
26
|
enums::v1::{CommandType, EventType, RetryState},
|
|
27
|
-
failure::v1::{
|
|
27
|
+
failure::v1::{ActivityFailureInfo, CanceledFailureInfo, Failure, failure::FailureInfo},
|
|
28
28
|
history::v1::{
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
ActivityTaskTimedOutEventAttributes,
|
|
29
|
+
ActivityTaskCanceledEventAttributes, ActivityTaskCompletedEventAttributes,
|
|
30
|
+
ActivityTaskFailedEventAttributes, ActivityTaskTimedOutEventAttributes, history_event,
|
|
32
31
|
},
|
|
33
32
|
},
|
|
34
33
|
};
|
|
@@ -128,16 +127,11 @@ impl ActivityMachine {
|
|
|
128
127
|
);
|
|
129
128
|
OnEventWrapper::on_event_mut(&mut s, ActivityMachineEvents::Schedule)
|
|
130
129
|
.expect("Scheduling activities doesn't fail");
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
attributes: Some(schedule_activity_cmd_to_api(
|
|
130
|
+
NewMachineWithCommand {
|
|
131
|
+
command: schedule_activity_cmd_to_api(
|
|
134
132
|
s.shared_state().attrs.clone(),
|
|
135
133
|
use_compatible_version,
|
|
136
|
-
)
|
|
137
|
-
user_metadata: Default::default(),
|
|
138
|
-
};
|
|
139
|
-
NewMachineWithCommand {
|
|
140
|
-
command,
|
|
134
|
+
),
|
|
141
135
|
machine: s.into(),
|
|
142
136
|
}
|
|
143
137
|
}
|
|
@@ -169,6 +163,45 @@ impl ActivityMachine {
|
|
|
169
163
|
is_local: false,
|
|
170
164
|
}
|
|
171
165
|
}
|
|
166
|
+
|
|
167
|
+
pub(super) fn cancel(&mut self) -> Result<Vec<MachineResponse>, MachineError<WFMachinesError>> {
|
|
168
|
+
if matches!(
|
|
169
|
+
self.state(),
|
|
170
|
+
ActivityMachineState::Completed(_)
|
|
171
|
+
| ActivityMachineState::Canceled(_)
|
|
172
|
+
| ActivityMachineState::Failed(_)
|
|
173
|
+
| ActivityMachineState::TimedOut(_)
|
|
174
|
+
) {
|
|
175
|
+
// Ignore attempted cancels in terminal states
|
|
176
|
+
debug!(
|
|
177
|
+
"Attempted to cancel already resolved activity (seq {})",
|
|
178
|
+
self.shared_state.attrs.seq
|
|
179
|
+
);
|
|
180
|
+
return Ok(vec![]);
|
|
181
|
+
}
|
|
182
|
+
let event = match self.shared_state.cancellation_type {
|
|
183
|
+
ActivityCancellationType::Abandon => ActivityMachineEvents::Abandon,
|
|
184
|
+
_ => ActivityMachineEvents::Cancel,
|
|
185
|
+
};
|
|
186
|
+
let vec = OnEventWrapper::on_event_mut(self, event)?;
|
|
187
|
+
let res = vec
|
|
188
|
+
.into_iter()
|
|
189
|
+
.flat_map(|amc| match amc {
|
|
190
|
+
ActivityMachineCommand::RequestCancellation(cmd) => {
|
|
191
|
+
self.machine_responses_from_cancel_request(cmd)
|
|
192
|
+
}
|
|
193
|
+
ActivityMachineCommand::Cancel(details) => {
|
|
194
|
+
vec![self.create_cancelation_resolve(details).into()]
|
|
195
|
+
}
|
|
196
|
+
x => panic!("Invalid cancel event response {x:?}"),
|
|
197
|
+
})
|
|
198
|
+
.collect();
|
|
199
|
+
Ok(res)
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
pub(super) fn was_cancelled_before_sent_to_server(&self) -> bool {
|
|
203
|
+
self.shared_state().cancelled_before_sent
|
|
204
|
+
}
|
|
172
205
|
}
|
|
173
206
|
|
|
174
207
|
impl TryFrom<HistEventData> for ActivityMachineEvents {
|
|
@@ -245,7 +278,7 @@ impl TryFrom<HistEventData> for ActivityMachineEvents {
|
|
|
245
278
|
_ => {
|
|
246
279
|
return Err(WFMachinesError::Nondeterminism(format!(
|
|
247
280
|
"Activity machine does not handle this event: {e}"
|
|
248
|
-
)))
|
|
281
|
+
)));
|
|
249
282
|
}
|
|
250
283
|
})
|
|
251
284
|
}
|
|
@@ -259,28 +292,32 @@ impl WFMachinesAdapter for ActivityMachine {
|
|
|
259
292
|
) -> Result<Vec<MachineResponse>, WFMachinesError> {
|
|
260
293
|
Ok(match my_command {
|
|
261
294
|
ActivityMachineCommand::Complete(result) => {
|
|
262
|
-
vec![
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
295
|
+
vec![
|
|
296
|
+
ResolveActivity {
|
|
297
|
+
seq: self.shared_state.attrs.seq,
|
|
298
|
+
result: Some(ActivityResolution {
|
|
299
|
+
status: Some(activity_resolution::Status::Completed(ar::Success {
|
|
300
|
+
result: convert_payloads(event_info, result)?,
|
|
301
|
+
})),
|
|
302
|
+
}),
|
|
303
|
+
is_local: false,
|
|
304
|
+
}
|
|
305
|
+
.into(),
|
|
306
|
+
]
|
|
272
307
|
}
|
|
273
308
|
ActivityMachineCommand::Fail(failure) => {
|
|
274
|
-
vec![
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
309
|
+
vec![
|
|
310
|
+
ResolveActivity {
|
|
311
|
+
seq: self.shared_state.attrs.seq,
|
|
312
|
+
result: Some(ActivityResolution {
|
|
313
|
+
status: Some(activity_resolution::Status::Failed(ar::Failure {
|
|
314
|
+
failure: Some(failure),
|
|
315
|
+
})),
|
|
316
|
+
}),
|
|
317
|
+
is_local: false,
|
|
318
|
+
}
|
|
319
|
+
.into(),
|
|
320
|
+
]
|
|
284
321
|
}
|
|
285
322
|
ActivityMachineCommand::RequestCancellation(c) => {
|
|
286
323
|
self.machine_responses_from_cancel_request(c)
|
|
@@ -304,47 +341,6 @@ impl TryFrom<CommandType> for ActivityMachineEvents {
|
|
|
304
341
|
}
|
|
305
342
|
}
|
|
306
343
|
|
|
307
|
-
impl Cancellable for ActivityMachine {
|
|
308
|
-
fn cancel(&mut self) -> Result<Vec<MachineResponse>, MachineError<Self::Error>> {
|
|
309
|
-
if matches!(
|
|
310
|
-
self.state(),
|
|
311
|
-
ActivityMachineState::Completed(_)
|
|
312
|
-
| ActivityMachineState::Canceled(_)
|
|
313
|
-
| ActivityMachineState::Failed(_)
|
|
314
|
-
| ActivityMachineState::TimedOut(_)
|
|
315
|
-
) {
|
|
316
|
-
// Ignore attempted cancels in terminal states
|
|
317
|
-
debug!(
|
|
318
|
-
"Attempted to cancel already resolved activity (seq {})",
|
|
319
|
-
self.shared_state.attrs.seq
|
|
320
|
-
);
|
|
321
|
-
return Ok(vec![]);
|
|
322
|
-
}
|
|
323
|
-
let event = match self.shared_state.cancellation_type {
|
|
324
|
-
ActivityCancellationType::Abandon => ActivityMachineEvents::Abandon,
|
|
325
|
-
_ => ActivityMachineEvents::Cancel,
|
|
326
|
-
};
|
|
327
|
-
let vec = OnEventWrapper::on_event_mut(self, event)?;
|
|
328
|
-
let res = vec
|
|
329
|
-
.into_iter()
|
|
330
|
-
.flat_map(|amc| match amc {
|
|
331
|
-
ActivityMachineCommand::RequestCancellation(cmd) => {
|
|
332
|
-
self.machine_responses_from_cancel_request(cmd)
|
|
333
|
-
}
|
|
334
|
-
ActivityMachineCommand::Cancel(details) => {
|
|
335
|
-
vec![self.create_cancelation_resolve(details).into()]
|
|
336
|
-
}
|
|
337
|
-
x => panic!("Invalid cancel event response {x:?}"),
|
|
338
|
-
})
|
|
339
|
-
.collect();
|
|
340
|
-
Ok(res)
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
fn was_cancelled_before_sent_to_server(&self) -> bool {
|
|
344
|
-
self.shared_state().cancelled_before_sent
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
|
|
348
344
|
#[derive(Clone)]
|
|
349
345
|
pub(super) struct SharedState {
|
|
350
346
|
scheduled_event_id: i64,
|
|
@@ -757,7 +753,7 @@ fn new_cancel_failure(dat: &SharedState, attrs: ActivityTaskCanceledEventAttribu
|
|
|
757
753
|
message: "Activity cancelled".to_string(),
|
|
758
754
|
cause: Some(Box::from(Failure {
|
|
759
755
|
failure_info: Some(FailureInfo::CanceledFailureInfo(CanceledFailureInfo {
|
|
760
|
-
details: attrs.details
|
|
756
|
+
details: attrs.details,
|
|
761
757
|
})),
|
|
762
758
|
..Default::default()
|
|
763
759
|
})),
|
|
@@ -808,14 +804,14 @@ mod test {
|
|
|
808
804
|
use crate::{
|
|
809
805
|
internal_flags::InternalFlags,
|
|
810
806
|
replay::TestHistoryBuilder,
|
|
811
|
-
test_help::{
|
|
812
|
-
worker::workflow::{machines::Machines
|
|
807
|
+
test_help::{MockPollCfg, ResponseType, build_fake_sdk},
|
|
808
|
+
worker::workflow::{OutgoingJob, machines::Machines},
|
|
813
809
|
};
|
|
814
810
|
use std::{cell::RefCell, mem::discriminant, rc::Rc};
|
|
815
811
|
use temporal_sdk::{ActivityOptions, CancellableFuture, WfContext, WorkflowFunction};
|
|
816
812
|
use temporal_sdk_core_protos::{
|
|
817
|
-
coresdk::workflow_activation::{workflow_activation_job, WorkflowActivationJob},
|
|
818
813
|
DEFAULT_WORKFLOW_TYPE,
|
|
814
|
+
coresdk::workflow_activation::{WorkflowActivationJob, workflow_activation_job},
|
|
819
815
|
};
|
|
820
816
|
use temporal_sdk_core_test_utils::interceptors::ActivationAssertionsInterceptor;
|
|
821
817
|
|
|
@@ -881,7 +877,7 @@ mod test {
|
|
|
881
877
|
attrs: Default::default(),
|
|
882
878
|
cancellation_type: Default::default(),
|
|
883
879
|
cancelled_before_sent: false,
|
|
884
|
-
internal_flags: Rc::new(RefCell::new(InternalFlags::
|
|
880
|
+
internal_flags: Rc::new(RefCell::new(InternalFlags::default())),
|
|
885
881
|
},
|
|
886
882
|
);
|
|
887
883
|
let cmds = s.cancel().unwrap();
|
|
@@ -899,7 +895,7 @@ mod test {
|
|
|
899
895
|
cancellation_type: ActivityCancellationType::Abandon.into(),
|
|
900
896
|
..Default::default()
|
|
901
897
|
},
|
|
902
|
-
Rc::new(RefCell::new(InternalFlags::
|
|
898
|
+
Rc::new(RefCell::new(InternalFlags::default())),
|
|
903
899
|
true,
|
|
904
900
|
);
|
|
905
901
|
let mut s = if let Machines::ActivityMachine(am) = s.machine {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
use super::{
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
EventInfo, NewMachineWithCommand, OnEventWrapper, WFMachinesAdapter, WFMachinesError,
|
|
3
|
+
workflow_machines::MachineResponse,
|
|
4
4
|
};
|
|
5
5
|
use crate::worker::workflow::machines::HistEventData;
|
|
6
|
-
use rustfsm::{
|
|
6
|
+
use rustfsm::{StateMachine, TransitionResult, fsm};
|
|
7
7
|
use std::convert::TryFrom;
|
|
8
8
|
use temporal_sdk_core_protos::{
|
|
9
9
|
coresdk::{
|
|
@@ -11,9 +11,9 @@ use temporal_sdk_core_protos::{
|
|
|
11
11
|
workflow_activation::ResolveRequestCancelExternalWorkflow,
|
|
12
12
|
},
|
|
13
13
|
temporal::api::{
|
|
14
|
-
command::v1::{
|
|
14
|
+
command::v1::{RequestCancelExternalWorkflowExecutionCommandAttributes, command},
|
|
15
15
|
enums::v1::{CancelExternalWorkflowExecutionFailedCause, CommandType, EventType},
|
|
16
|
-
failure::v1::{
|
|
16
|
+
failure::v1::{ApplicationFailureInfo, Failure, failure::FailureInfo},
|
|
17
17
|
history::v1::history_event,
|
|
18
18
|
},
|
|
19
19
|
};
|
|
@@ -75,13 +75,8 @@ pub(super) fn new_external_cancel(
|
|
|
75
75
|
reason,
|
|
76
76
|
},
|
|
77
77
|
);
|
|
78
|
-
let cmd = Command {
|
|
79
|
-
command_type: CommandType::RequestCancelExternalWorkflowExecution as i32,
|
|
80
|
-
attributes: Some(cmd_attrs),
|
|
81
|
-
user_metadata: Default::default(),
|
|
82
|
-
};
|
|
83
78
|
NewMachineWithCommand {
|
|
84
|
-
command:
|
|
79
|
+
command: cmd_attrs,
|
|
85
80
|
machine: s.into(),
|
|
86
81
|
}
|
|
87
82
|
}
|
|
@@ -182,11 +177,13 @@ impl WFMachinesAdapter for CancelExternalMachine {
|
|
|
182
177
|
) -> Result<Vec<MachineResponse>, WFMachinesError> {
|
|
183
178
|
Ok(match my_command {
|
|
184
179
|
CancelExternalCommand::Requested => {
|
|
185
|
-
vec![
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
180
|
+
vec![
|
|
181
|
+
ResolveRequestCancelExternalWorkflow {
|
|
182
|
+
seq: self.shared_state.seq,
|
|
183
|
+
failure: None,
|
|
184
|
+
}
|
|
185
|
+
.into(),
|
|
186
|
+
]
|
|
190
187
|
}
|
|
191
188
|
CancelExternalCommand::Failed(f) => {
|
|
192
189
|
let reason = match f {
|
|
@@ -194,44 +191,47 @@ impl WFMachinesAdapter for CancelExternalMachine {
|
|
|
194
191
|
CancelExternalWorkflowExecutionFailedCause::ExternalWorkflowExecutionNotFound
|
|
195
192
|
| CancelExternalWorkflowExecutionFailedCause::NamespaceNotFound => "not found"
|
|
196
193
|
};
|
|
197
|
-
vec![
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
ApplicationFailureInfo
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
194
|
+
vec![
|
|
195
|
+
ResolveRequestCancelExternalWorkflow {
|
|
196
|
+
seq: self.shared_state.seq,
|
|
197
|
+
failure: Some(Failure {
|
|
198
|
+
message: format!("Unable to cancel external workflow because {reason}"),
|
|
199
|
+
failure_info: Some(FailureInfo::ApplicationFailureInfo(
|
|
200
|
+
ApplicationFailureInfo {
|
|
201
|
+
r#type: f.to_string(),
|
|
202
|
+
..Default::default()
|
|
203
|
+
},
|
|
204
|
+
)),
|
|
205
|
+
..Default::default()
|
|
206
|
+
}),
|
|
207
|
+
}
|
|
208
|
+
.into(),
|
|
209
|
+
]
|
|
211
210
|
}
|
|
212
211
|
})
|
|
213
212
|
}
|
|
214
213
|
}
|
|
215
214
|
|
|
216
|
-
impl Cancellable for CancelExternalMachine {}
|
|
217
|
-
|
|
218
215
|
#[cfg(test)]
|
|
219
216
|
mod tests {
|
|
220
217
|
use super::*;
|
|
221
218
|
use crate::{
|
|
222
219
|
replay::TestHistoryBuilder,
|
|
223
|
-
test_help::{
|
|
220
|
+
test_help::{MockPollCfg, build_fake_sdk},
|
|
224
221
|
};
|
|
225
222
|
use temporal_sdk::{WfContext, WorkflowResult};
|
|
226
223
|
use temporal_sdk_core_protos::DEFAULT_WORKFLOW_TYPE;
|
|
227
224
|
|
|
228
225
|
async fn cancel_sender(ctx: WfContext) -> WorkflowResult<()> {
|
|
229
226
|
let res = ctx
|
|
230
|
-
.cancel_external(
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
227
|
+
.cancel_external(
|
|
228
|
+
NamespacedWorkflowExecution {
|
|
229
|
+
namespace: "some_namespace".to_string(),
|
|
230
|
+
workflow_id: "fake_wid".to_string(),
|
|
231
|
+
run_id: "fake_rid".to_string(),
|
|
232
|
+
},
|
|
233
|
+
"cancel reason".to_string(),
|
|
234
|
+
)
|
|
235
235
|
.await;
|
|
236
236
|
if res.is_err() {
|
|
237
237
|
Err(anyhow::anyhow!("Cancel fail!"))
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
use super::{
|
|
2
|
+
workflow_machines::MachineResponse, Cancellable, EventInfo, NewMachineWithCommand,
|
|
3
|
+
WFMachinesAdapter, WFMachinesError,
|
|
4
|
+
};
|
|
5
|
+
use crate::worker::workflow::machines::HistEventData;
|
|
6
|
+
use rustfsm::{fsm, StateMachine, TransitionResult};
|
|
7
|
+
use std::convert::TryFrom;
|
|
8
|
+
use temporal_sdk_core_protos::{
|
|
9
|
+
coresdk::workflow_activation::ResolveCancelNexusOperation,
|
|
10
|
+
temporal::api::{
|
|
11
|
+
command::v1::{command, RequestCancelNexusOperationCommandAttributes},
|
|
12
|
+
enums::v1::{CommandType, EventType},
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
fsm! {
|
|
17
|
+
pub(super)
|
|
18
|
+
name CancelNexusOpMachine;
|
|
19
|
+
command CancelNexusOpCommand;
|
|
20
|
+
error WFMachinesError;
|
|
21
|
+
shared_state SharedState;
|
|
22
|
+
|
|
23
|
+
RequestCancelNexusOpCommandCreated --(CommandRequestCancelNexusOpWorkflowExecution)
|
|
24
|
+
--> RequestCancelNexusOpCommandCreated;
|
|
25
|
+
|
|
26
|
+
RequestCancelNexusOpCommandCreated --(NexusOpCancelRequested, on_cancel_requested)
|
|
27
|
+
--> CancelRequested;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
#[derive(Default, Clone)]
|
|
31
|
+
pub(super) struct SharedState {
|
|
32
|
+
seq: u32,
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
#[derive(Debug, derive_more::Display)]
|
|
36
|
+
pub(super) enum CancelNexusOpCommand {
|
|
37
|
+
Requested,
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
pub(super) fn new_nexus_op_cancel(
|
|
41
|
+
seq: u32,
|
|
42
|
+
nexus_op_scheduled_event_id: i64,
|
|
43
|
+
) -> NewMachineWithCommand {
|
|
44
|
+
let s = CancelNexusOpMachine::from_parts(
|
|
45
|
+
RequestCancelNexusOpCommandCreated {}.into(),
|
|
46
|
+
SharedState { seq },
|
|
47
|
+
);
|
|
48
|
+
let cmd_attrs = command::Attributes::RequestCancelNexusOperationCommandAttributes(
|
|
49
|
+
RequestCancelNexusOperationCommandAttributes {
|
|
50
|
+
scheduled_event_id: nexus_op_scheduled_event_id,
|
|
51
|
+
},
|
|
52
|
+
);
|
|
53
|
+
NewMachineWithCommand {
|
|
54
|
+
command: cmd_attrs,
|
|
55
|
+
machine: s.into(),
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
#[derive(Default, Clone)]
|
|
60
|
+
pub(super) struct CancelRequested {}
|
|
61
|
+
|
|
62
|
+
#[derive(Default, Clone)]
|
|
63
|
+
pub(super) struct RequestCancelNexusOpCommandCreated {}
|
|
64
|
+
|
|
65
|
+
impl RequestCancelNexusOpCommandCreated {
|
|
66
|
+
pub(super) fn on_cancel_requested(self) -> CancelNexusOpMachineTransition<CancelRequested> {
|
|
67
|
+
TransitionResult::commands(vec![CancelNexusOpCommand::Requested])
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
impl TryFrom<HistEventData> for CancelNexusOpMachineEvents {
|
|
72
|
+
type Error = WFMachinesError;
|
|
73
|
+
|
|
74
|
+
fn try_from(e: HistEventData) -> Result<Self, Self::Error> {
|
|
75
|
+
let e = e.event;
|
|
76
|
+
Ok(match e.event_type() {
|
|
77
|
+
EventType::NexusOperationCancelRequested => Self::NexusOpCancelRequested,
|
|
78
|
+
_ => {
|
|
79
|
+
return Err(WFMachinesError::Nondeterminism(format!(
|
|
80
|
+
"Cancel external WF machine does not handle this event: {e}"
|
|
81
|
+
)))
|
|
82
|
+
}
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
impl TryFrom<CommandType> for CancelNexusOpMachineEvents {
|
|
88
|
+
type Error = ();
|
|
89
|
+
|
|
90
|
+
fn try_from(c: CommandType) -> Result<Self, Self::Error> {
|
|
91
|
+
Ok(match c {
|
|
92
|
+
CommandType::RequestCancelNexusOperation => {
|
|
93
|
+
Self::CommandRequestCancelNexusOpWorkflowExecution
|
|
94
|
+
}
|
|
95
|
+
_ => return Err(()),
|
|
96
|
+
})
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
impl WFMachinesAdapter for CancelNexusOpMachine {
|
|
101
|
+
fn adapt_response(
|
|
102
|
+
&self,
|
|
103
|
+
my_command: Self::Command,
|
|
104
|
+
_event_info: Option<EventInfo>,
|
|
105
|
+
) -> Result<Vec<MachineResponse>, WFMachinesError> {
|
|
106
|
+
Ok(match my_command {
|
|
107
|
+
CancelNexusOpCommand::Requested => {
|
|
108
|
+
vec![ResolveCancelNexusOperation {
|
|
109
|
+
seq: self.shared_state.seq,
|
|
110
|
+
}
|
|
111
|
+
.into()]
|
|
112
|
+
}
|
|
113
|
+
})
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
impl Cancellable for CancelNexusOpMachine {}
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
use super::{
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
EventInfo, NewMachineWithCommand, OnEventWrapper, WFMachinesAdapter, WFMachinesError,
|
|
3
|
+
workflow_machines::MachineResponse,
|
|
4
4
|
};
|
|
5
5
|
use crate::worker::workflow::machines::HistEventData;
|
|
6
|
-
use rustfsm::{
|
|
6
|
+
use rustfsm::{StateMachine, TransitionResult, fsm};
|
|
7
7
|
use std::convert::TryFrom;
|
|
8
8
|
use temporal_sdk_core_protos::{
|
|
9
9
|
coresdk::workflow_commands::CancelWorkflowExecution,
|
|
10
|
-
temporal::api::{
|
|
11
|
-
command::v1::Command,
|
|
12
|
-
enums::v1::{CommandType, EventType},
|
|
13
|
-
},
|
|
10
|
+
temporal::api::enums::v1::{CommandType, EventType},
|
|
14
11
|
};
|
|
15
12
|
|
|
16
13
|
fsm! {
|
|
@@ -34,13 +31,8 @@ pub(super) fn cancel_workflow(attribs: CancelWorkflowExecution) -> NewMachineWit
|
|
|
34
31
|
let mut machine = CancelWorkflowMachine::from_parts(Created {}.into(), ());
|
|
35
32
|
OnEventWrapper::on_event_mut(&mut machine, CancelWorkflowMachineEvents::Schedule)
|
|
36
33
|
.expect("Scheduling continue as new machine doesn't fail");
|
|
37
|
-
let command = Command {
|
|
38
|
-
command_type: CommandType::CancelWorkflowExecution as i32,
|
|
39
|
-
attributes: Some(attribs.into()),
|
|
40
|
-
user_metadata: Default::default(),
|
|
41
|
-
};
|
|
42
34
|
NewMachineWithCommand {
|
|
43
|
-
command,
|
|
35
|
+
command: attribs.into(),
|
|
44
36
|
machine: machine.into(),
|
|
45
37
|
}
|
|
46
38
|
}
|
|
@@ -78,7 +70,7 @@ impl TryFrom<HistEventData> for CancelWorkflowMachineEvents {
|
|
|
78
70
|
_ => {
|
|
79
71
|
return Err(WFMachinesError::Nondeterminism(format!(
|
|
80
72
|
"Cancel workflow machine does not handle this event: {e}"
|
|
81
|
-
)))
|
|
73
|
+
)));
|
|
82
74
|
}
|
|
83
75
|
})
|
|
84
76
|
}
|
|
@@ -105,17 +97,15 @@ impl WFMachinesAdapter for CancelWorkflowMachine {
|
|
|
105
97
|
}
|
|
106
98
|
}
|
|
107
99
|
|
|
108
|
-
impl Cancellable for CancelWorkflowMachine {}
|
|
109
|
-
|
|
110
100
|
#[cfg(test)]
|
|
111
101
|
mod tests {
|
|
112
102
|
use super::*;
|
|
113
|
-
use crate::test_help::{build_fake_sdk, canned_histories
|
|
103
|
+
use crate::test_help::{MockPollCfg, build_fake_sdk, canned_histories};
|
|
114
104
|
use std::time::Duration;
|
|
115
105
|
use temporal_sdk::{WfContext, WfExitValue, WorkflowResult};
|
|
116
106
|
use temporal_sdk_core_protos::{
|
|
117
|
-
coresdk::workflow_activation::{workflow_activation_job, WorkflowActivationJob},
|
|
118
107
|
DEFAULT_WORKFLOW_TYPE,
|
|
108
|
+
coresdk::workflow_activation::{WorkflowActivationJob, workflow_activation_job},
|
|
119
109
|
};
|
|
120
110
|
use temporal_sdk_core_test_utils::interceptors::ActivationAssertionsInterceptor;
|
|
121
111
|
|