Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions core/src/worker/workflow/machines/nexus_operation_state_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ fsm! {
ScheduledEventRecorded
--(NexusOperationTimedOut(NexusOperationTimedOutEventAttributes), on_timed_out)--> TimedOut;
ScheduledEventRecorded
--(NexusOperationStarted(NexusOperationStartedEventAttributes), on_started)--> Started;
--(NexusOperationStarted(NexusOperationStartedEventAttributes), shared on_started)--> Started;

Started --(Cancel, shared on_issue_cancel)--> Started;
Started --(Cancel, shared on_issue_cancel)--> Cancelled;
Expand Down Expand Up @@ -113,6 +113,7 @@ pub(super) struct SharedState {
cancelled_before_sent: bool,
cancel_sent: bool,
cancel_type: NexusOperationCancellationType,
operation_token: Option<String>,
}

impl NexusOperationMachine {
Expand All @@ -128,6 +129,7 @@ impl NexusOperationMachine {
cancelled_before_sent: false,
cancel_sent: false,
cancel_type: attribs.cancellation_type(),
operation_token: None,
},
);
NewMachineWithCommand {
Expand Down Expand Up @@ -246,8 +248,10 @@ impl ScheduledEventRecorded {

pub(super) fn on_started(
self,
ss: &mut SharedState,
sa: NexusOperationStartedEventAttributes,
) -> NexusOperationMachineTransition<Started> {
ss.operation_token = Some(sa.operation_token.clone());
NexusOperationMachineTransition::commands([NexusOperationCommand::Start {
operation_token: sa.operation_token,
}])
Expand Down Expand Up @@ -496,6 +500,7 @@ impl WFMachinesAdapter for NexusOperationMachine {
status: Some(resolve_nexus_operation_start::Status::CancelledBeforeStart(
self.cancelled_failure(
"Nexus Operation cancelled before scheduled".to_owned(),
&self.shared_state.operation_token,
),
)),
}
Expand All @@ -506,6 +511,7 @@ impl WFMachinesAdapter for NexusOperationMachine {
status: Some(nexus_operation_result::Status::Cancelled(
self.cancelled_failure(
"Nexus Operation cancelled before scheduled".to_owned(),
&self.shared_state.operation_token,
),
)),
}),
Expand Down Expand Up @@ -584,6 +590,7 @@ impl WFMachinesAdapter for NexusOperationMachine {
status: Some(nexus_operation_result::Status::Cancelled(
self.cancelled_failure(
"Nexus operation cancelled after starting".to_owned(),
&self.shared_state.operation_token,
),
)),
}),
Expand All @@ -610,7 +617,7 @@ impl TryFrom<CommandType> for NexusOperationMachineEvents {
}

impl NexusOperationMachine {
fn cancelled_failure(&self, message: String) -> Failure {
fn cancelled_failure(&self, message: String, operation_token: &Option<String>) -> Failure {
Failure {
message,
cause: Some(Box::new(Failure {
Expand All @@ -624,7 +631,7 @@ impl NexusOperationMachine {
service: self.shared_state.service.clone(),
operation: self.shared_state.operation.clone(),
operation_id: "".to_string(),
operation_token: "".to_string(),
operation_token: operation_token.clone().unwrap_or_default(),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we have to do this anyway, may as well just not bother with the option and init this to empty string.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't see until after. Care enough to go back for it?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah, no biggie

},
)),
..Default::default()
Expand Down
10 changes: 5 additions & 5 deletions sdk-core-protos/protos/local/temporal/sdk/core/nexus/nexus.proto
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,15 @@ enum NexusTaskCancelReason {

// Controls at which point to report back to lang when a nexus operation is cancelled
enum NexusOperationCancellationType {
// Wait for operation cancellation completion. Default.
WAIT_CANCELLATION_COMPLETED = 0;
// Do not request cancellation of the nexus operation if already scheduled
ABANDON = 0;
ABANDON = 1;

// Initiate a cancellation request for the Nexus operation and immediately report cancellation
// to the caller. Note that it doesn't guarantee that cancellation is delivered to the operation if calling workflow exits before the delivery is done.
// If you want to ensure that cancellation is delivered to the operation, use WAIT_CANCELLATION_REQUESTED.
TRY_CANCEL = 1;
TRY_CANCEL = 2;
// Request cancellation of the operation and wait for confirmation that the request was received.
WAIT_CANCELLATION_REQUESTED = 2;
// Wait for operation cancellation completion. Default.
WAIT_CANCELLATION_COMPLETED = 3;
WAIT_CANCELLATION_REQUESTED = 3;
}