From cce804a534696d49b2bc86492fb9d664f4363a23 Mon Sep 17 00:00:00 2001 From: Jan Date: Mon, 12 Jul 2021 10:12:45 +0200 Subject: [PATCH] :zap: Simplify bull error handling (#1983) --- packages/cli/src/WorkflowRunner.ts | 48 ++++++++++-------------------- 1 file changed, 15 insertions(+), 33 deletions(-) diff --git a/packages/cli/src/WorkflowRunner.ts b/packages/cli/src/WorkflowRunner.ts index d9742fce97..160030d748 100644 --- a/packages/cli/src/WorkflowRunner.ts +++ b/packages/cli/src/WorkflowRunner.ts @@ -275,11 +275,11 @@ export class WorkflowRunner { // data to editor-UI is not needed. hooks.executeHookFunctions('workflowExecuteBefore', []); } catch (error) { - // We use "getWorkflowHooksIntegrated" here as we are just integrated in the "workflowExecuteAfter" - // hook anyway and other get so ignored - const hooks = WorkflowExecuteAdditionalData.getWorkflowHooksIntegrated(data.executionMode, executionId, data.workflowData, { retryOf: data.retryOf ? data.retryOf.toString() : undefined }); + // We use "getWorkflowHooksWorkerExecuter" as "getWorkflowHooksWorkerMain" does not contain the + // "workflowExecuteAfter" which we require. + const hooks = WorkflowExecuteAdditionalData.getWorkflowHooksWorkerExecuter(data.executionMode, executionId, data.workflowData, { retryOf: data.retryOf ? data.retryOf.toString() : undefined }); await this.processError(error, new Date(), data.executionMode, executionId, hooks); - return executionId; + throw error; } const workflowExecution: PCancelable = new PCancelable(async (resolve, reject, onCancel) => { @@ -287,19 +287,14 @@ export class WorkflowRunner { onCancel(async () => { await Queue.getInstance().stopJob(job); - const fullRunData :IRun = { - data: { - resultData: { - error: new WorkflowOperationError('Workflow-Execution has been canceled!'), - runData: {}, - }, - }, - mode: data.executionMode, - startedAt: new Date(), - stoppedAt: new Date(), - }; - this.activeExecutions.remove(executionId, fullRunData); - resolve(fullRunData); + // We use "getWorkflowHooksWorkerExecuter" as "getWorkflowHooksWorkerMain" does not contain the + // "workflowExecuteAfter" which we require. + const hooksWorker = WorkflowExecuteAdditionalData.getWorkflowHooksWorkerExecuter(data.executionMode, executionId, data.workflowData, { retryOf: data.retryOf ? data.retryOf.toString() : undefined }); + + const error = new WorkflowOperationError('Workflow-Execution has been canceled!'); + await this.processError(error, new Date(), data.executionMode, executionId, hooksWorker); + + reject(error); }); const jobData: Promise = job.finished(); @@ -351,6 +346,8 @@ export class WorkflowRunner { clearWatchdogInterval(); } } catch (error) { + // We use "getWorkflowHooksWorkerExecuter" as "getWorkflowHooksWorkerMain" does not contain the + // "workflowExecuteAfter" which we require. const hooks = WorkflowExecuteAdditionalData.getWorkflowHooksWorkerExecuter(data.executionMode, executionId, data.workflowData, { retryOf: data.retryOf ? data.retryOf.toString() : undefined }); Logger.error(`Problem with execution ${executionId}: ${error.message}. Aborting.`); if (clearWatchdogInterval !== undefined) { @@ -358,24 +355,9 @@ export class WorkflowRunner { } await this.processError(error, new Date(), data.executionMode, executionId, hooks); - const fullRunData :IRun = { - data: { - resultData: { - error, - runData: {}, - }, - }, - mode: data.executionMode, - startedAt: new Date(), - stoppedAt: new Date(), - }; - this.activeExecutions.remove(executionId, fullRunData); - resolve(fullRunData); - return; + reject(error); } - - const executionDb = await Db.collections.Execution!.findOne(executionId) as IExecutionFlattedDb; const fullExecutionData = ResponseHelper.unflattenExecutionData(executionDb) as IExecutionResponse; const runData = {