From e0ea97af8d7aaa014680f5f9d5702d1cafd49757 Mon Sep 17 00:00:00 2001 From: Michael Auerswald Date: Fri, 17 Mar 2023 18:02:49 +0100 Subject: [PATCH] fix(core): Fix calling error workflows in main mode recovery (#5698) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix calling error workflows in main mode recovery * cleanup * remove WorkflowExecuteAdditionalData export from index * revert refactor to fix test * Update index.ts --------- Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ --- .../eventbus/MessageEventBus/recoverEvents.ts | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/packages/cli/src/eventbus/MessageEventBus/recoverEvents.ts b/packages/cli/src/eventbus/MessageEventBus/recoverEvents.ts index 88399233f2..af95df2e88 100644 --- a/packages/cli/src/eventbus/MessageEventBus/recoverEvents.ts +++ b/packages/cli/src/eventbus/MessageEventBus/recoverEvents.ts @@ -10,6 +10,7 @@ import { workflowExecutionCompleted } from '../../events/WorkflowStatistics'; import { eventBus } from './MessageEventBus'; import { Container } from 'typedi'; import { InternalHooks } from '@/InternalHooks'; +import { getWorkflowHooksMain } from '@/WorkflowExecuteAdditionalData'; export async function recoverExecutionDataFromEventLogMessages( executionId: string, @@ -122,9 +123,6 @@ export async function recoverExecutionDataFromEventLogMessages( } } - if (!executionData.resultData.error && workflowError) { - executionData.resultData.error = workflowError; - } if (!lastNodeRunTimestamp) { const workflowEndedMessage = messages.find((message) => ( @@ -138,6 +136,11 @@ export async function recoverExecutionDataFromEventLogMessages( if (workflowEndedMessage) { lastNodeRunTimestamp = workflowEndedMessage.ts; } else { + if (!workflowError) { + workflowError = new WorkflowOperationError( + 'Workflow did not finish, possible out-of-memory issue', + ); + } const workflowStartedMessage = messages.find( (message) => message.eventName === 'n8n.workflow.started', ); @@ -146,6 +149,11 @@ export async function recoverExecutionDataFromEventLogMessages( } } } + + if (!executionData.resultData.error && workflowError) { + executionData.resultData.error = workflowError; + } + if (applyToDb) { await Db.collections.Execution.update(executionId, { data: stringify(executionData), @@ -174,6 +182,20 @@ export async function recoverExecutionDataFromEventLogMessages( stoppedAt: lastNodeRunTimestamp?.toJSDate(), status: 'crashed', }; + const workflowHooks = getWorkflowHooksMain( + { + userId: '', + workflowData: executionEntry.workflowData, + executionMode: executionEntry.mode, + executionData, + runData: executionData.resultData.runData, + retryOf: executionEntry.retryOf, + }, + executionId, + ); + + // execute workflowExecuteAfter hook to trigger error workflow + await workflowHooks.executeHookFunctions('workflowExecuteAfter', [iRunData]); // calling workflowExecutionCompleted directly because the eventEmitter is not up yet at this point await workflowExecutionCompleted(executionEntry.workflowData, iRunData);