Skip to content

Commit

Permalink
fix(core): Fix canceled execution status (#6142)
Browse files Browse the repository at this point in the history
  • Loading branch information
flipswitchingmonkey authored May 2, 2023
1 parent 06fa6f1 commit 839a56a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
6 changes: 6 additions & 0 deletions packages/cli/src/InternalHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,13 +290,19 @@ 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;
if (runData?.status === 'crashed') {
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';
}
Expand Down
10 changes: 8 additions & 2 deletions packages/cli/src/WorkflowExecuteAdditionalData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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') ||
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/WorkflowRunnerProcess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/WorkflowExecute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -1304,7 +1308,6 @@ export class WorkflowExecute {
// Static data of workflow changed
newStaticData = workflow.staticData;
}

await this.executeHook('workflowExecuteAfter', [fullRunData, newStaticData]);

if (closeFunction) {
Expand Down

0 comments on commit 839a56a

Please sign in to comment.