Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): Fix calling error workflows in main mode recovery #5698

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions packages/cli/src/eventbus/MessageEventBus/recoverEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { workflowExecutionCompleted } from '../../events/WorkflowStatistics';
import { eventBus } from './MessageEventBus';
import { Container } from 'typedi';
import { InternalHooks } from '@/InternalHooks';
import { WorkflowExecuteAdditionalData } from '../..';
netroy marked this conversation as resolved.
Show resolved Hide resolved

export async function recoverExecutionDataFromEventLogMessages(
executionId: string,
Expand Down Expand Up @@ -122,9 +123,6 @@ export async function recoverExecutionDataFromEventLogMessages(
}
}

if (!executionData.resultData.error && workflowError) {
executionData.resultData.error = workflowError;
}
if (!lastNodeRunTimestamp) {
const workflowEndedMessage = messages.find((message) =>
(
Expand All @@ -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',
);
Expand All @@ -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),
Expand Down Expand Up @@ -174,6 +182,20 @@ export async function recoverExecutionDataFromEventLogMessages(
stoppedAt: lastNodeRunTimestamp?.toJSDate(),
status: 'crashed',
};
const workflowHooks = WorkflowExecuteAdditionalData.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);
Expand Down