Skip to content

Commit

Permalink
handle cancellation properly
Browse files Browse the repository at this point in the history
  • Loading branch information
netroy committed Nov 22, 2023
1 parent ff92a6b commit 4c09e9e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 41 deletions.
1 change: 1 addition & 0 deletions packages/cli/src/ActiveExecutions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ export class ActiveExecutions {
} else {
// Workflow is running in current process
this.activeExecutions[executionId].workflowExecution!.cancel();
setTimeout(() => this.remove(executionId), 10);
}

return this.getPostExecutePromise(executionId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ export class ExecutionRepository extends Repository<ExecutionEntity> {

async markAsCrashed(executionIds: string[]) {
await this.update(
{ id: In(executionIds) },
{ id: In(executionIds), status: In(['new', 'running']) },
{
status: 'crashed',
stoppedAt: new Date(),
Expand Down
8 changes: 7 additions & 1 deletion packages/core/src/WorkflowExecute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -827,8 +827,14 @@ export class WorkflowExecute {

onCancel.shouldReject = false;
onCancel(() => {
this.abortController.abort();
gotCancel = true;
this.abortController.abort();
void this.processSuccessExecution(
startedAt,
workflow,
new WorkflowOperationError('Workflow has been canceled!'),
closeFunction,
);
});

const returnPromise = (async () => {
Expand Down
43 changes: 4 additions & 39 deletions packages/editor-ui/src/mixins/pushConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import type {
IWorkflowBase,
SubworkflowOperationError,
IExecuteContextData,
NodeOperationError,
} from 'n8n-workflow';
import { TelemetryHelpers } from 'n8n-workflow';

Expand Down Expand Up @@ -464,55 +463,21 @@ export const pushConnection = defineComponent({
type: 'error',
duration: 0,
});
} else if (
runDataExecuted.data.resultData.error?.name === 'NodeOperationError' &&
(runDataExecuted.data.resultData.error as NodeOperationError).functionality ===
'configuration-node'
) {
// If the error is a configuration error of the node itself doesn't get executed so we can't use lastNodeExecuted for the title
} else {
let title: string;
const nodeError = runDataExecuted.data.resultData.error as NodeOperationError;
if (nodeError.node.name) {
title = `Error in sub-node ‘${nodeError.node.name}‘`;
if (runDataExecuted.data.resultData.lastNodeExecuted) {
title = `Problem in node ‘${runDataExecuted.data.resultData.lastNodeExecuted}‘`;
} else {
title = 'Problem executing workflow';
}

this.showMessage({
title,
message:
(nodeError?.description ?? runDataExecutedErrorMessage) +
this.$locale.baseText('pushConnection.executionError.openNode', {
interpolate: {
node: nodeError.node.name,
},
}),
message: runDataExecutedErrorMessage,
type: 'error',
duration: 0,
dangerouslyUseHTMLString: true,
});
} else {
let title: string;
const isManualExecutionCancelled =
runDataExecutedErrorMessage === 'AbortError' ||
(runDataExecuted.mode === 'manual' && runDataExecuted.status === 'canceled');

// Do not show the error message if the workflow got canceled manually
if (!isManualExecutionCancelled) {
if (runDataExecuted.data.resultData.lastNodeExecuted) {
title = `Problem in node ‘${runDataExecuted.data.resultData.lastNodeExecuted}‘`;
} else {
title = 'Problem executing workflow';
}

this.showMessage({
title,
message: runDataExecutedErrorMessage,
type: 'error',
duration: 0,
dangerouslyUseHTMLString: true,
});
}
}
} else {
// Workflow did execute without a problem
Expand Down

0 comments on commit 4c09e9e

Please sign in to comment.