From 839a56a682674baf44d5beececdbe677d18c0d89 Mon Sep 17 00:00:00 2001 From: Michael Auerswald Date: Tue, 2 May 2023 10:37:35 +0200 Subject: [PATCH] fix(core): Fix canceled execution status (#6142) --- packages/cli/src/InternalHooks.ts | 6 ++++++ packages/cli/src/WorkflowExecuteAdditionalData.ts | 10 ++++++++-- packages/cli/src/WorkflowRunnerProcess.ts | 2 ++ packages/core/src/WorkflowExecute.ts | 5 ++++- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/packages/cli/src/InternalHooks.ts b/packages/cli/src/InternalHooks.ts index dd29b0874e..55793c0528 100644 --- a/packages/cli/src/InternalHooks.ts +++ b/packages/cli/src/InternalHooks.ts @@ -290,6 +290,10 @@ export class InternalHooks implements IInternalHooksClass { properties.user_id = userId; } + if (runData?.data.resultData.error?.message?.includes('canceled')) { + runData.status = 'canceled'; + } + properties.success = !!runData?.finished; let executionStatus: ExecutionStatus; @@ -297,6 +301,8 @@ export class InternalHooks implements IInternalHooksClass { executionStatus = 'crashed'; } else if (runData?.status === 'waiting' || runData?.data?.waitTill) { executionStatus = 'waiting'; + } else if (runData?.status === 'canceled') { + executionStatus = 'canceled'; } else { executionStatus = properties.success ? 'success' : 'failed'; } diff --git a/packages/cli/src/WorkflowExecuteAdditionalData.ts b/packages/cli/src/WorkflowExecuteAdditionalData.ts index f958d3a495..7f6f26f64b 100644 --- a/packages/cli/src/WorkflowExecuteAdditionalData.ts +++ b/packages/cli/src/WorkflowExecuteAdditionalData.ts @@ -583,9 +583,12 @@ function hookFunctionsSave(parentProcessMode?: string): IWorkflowExecuteHooks { } const workflowHasCrashed = fullRunData.status === 'crashed'; - const workflowDidSucceed = !fullRunData.data.resultData.error && !workflowHasCrashed; + const workflowWasCanceled = fullRunData.status === 'canceled'; + const workflowDidSucceed = + !fullRunData.data.resultData.error && !workflowHasCrashed && !workflowWasCanceled; let workflowStatusFinal: ExecutionStatus = workflowDidSucceed ? 'success' : 'failed'; if (workflowHasCrashed) workflowStatusFinal = 'crashed'; + if (workflowWasCanceled) workflowStatusFinal = 'canceled'; if ( (workflowDidSucceed && saveDataSuccessExecution === 'none') || @@ -755,9 +758,12 @@ function hookFunctionsSaveWorker(): IWorkflowExecuteHooks { } const workflowHasCrashed = fullRunData.status === 'crashed'; - const workflowDidSucceed = !fullRunData.data.resultData.error && !workflowHasCrashed; + const workflowWasCanceled = fullRunData.status === 'canceled'; + const workflowDidSucceed = + !fullRunData.data.resultData.error && !workflowHasCrashed && !workflowWasCanceled; let workflowStatusFinal: ExecutionStatus = workflowDidSucceed ? 'success' : 'failed'; if (workflowHasCrashed) workflowStatusFinal = 'crashed'; + if (workflowWasCanceled) workflowStatusFinal = 'canceled'; if (!workflowDidSucceed) { executeErrorWorkflow( diff --git a/packages/cli/src/WorkflowRunnerProcess.ts b/packages/cli/src/WorkflowRunnerProcess.ts index 3b61ed11fa..0e4bb08137 100644 --- a/packages/cli/src/WorkflowRunnerProcess.ts +++ b/packages/cli/src/WorkflowRunnerProcess.ts @@ -472,6 +472,8 @@ process.on('message', async (message: IProcessMessage) => { ? new WorkflowOperationError('Workflow execution timed out!') : new WorkflowOperationError('Workflow-Execution has been canceled!'); + runData.status = message.type === 'timeout' ? 'failed' : 'canceled'; + // If there is any data send it to parent process, if execution timedout add the error await workflowRunner.workflowExecute.processSuccessExecution( workflowRunner.startedAt, diff --git a/packages/core/src/WorkflowExecute.ts b/packages/core/src/WorkflowExecute.ts index 00e7a3f84f..072105c76a 100644 --- a/packages/core/src/WorkflowExecute.ts +++ b/packages/core/src/WorkflowExecute.ts @@ -1286,12 +1286,16 @@ export class WorkflowExecute { message: executionError.message, stack: executionError.stack, } as ExecutionError; + if (executionError.message?.includes('canceled')) { + fullRunData.status = 'canceled'; + } } else if (this.runExecutionData.waitTill!) { // eslint-disable-next-line @typescript-eslint/restrict-template-expressions Logger.verbose(`Workflow execution will wait until ${this.runExecutionData.waitTill}`, { workflowId: workflow.id, }); fullRunData.waitTill = this.runExecutionData.waitTill; + fullRunData.status = 'waiting'; } else { Logger.verbose('Workflow execution finished successfully', { workflowId: workflow.id }); fullRunData.finished = true; @@ -1304,7 +1308,6 @@ export class WorkflowExecute { // Static data of workflow changed newStaticData = workflow.staticData; } - await this.executeHook('workflowExecuteAfter', [fullRunData, newStaticData]); if (closeFunction) {