mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-12 15:44:06 -08:00
fix(core): Ensure failed executions are saved in queue mode (#7744)
This PR adds `status` to run data so that `determineFinalExecutionStatus` resolves correctly on execution failure and removes the cleanup that is being duplicated in a worker hook. Followup to https://github.com/n8n-io/n8n/pull/7138 Should fix: - https://github.com/n8n-io/n8n/issues/7705 - https://linear.app/n8n/issue/PAY-964/no-execution-found-after-execution-fails - https://linear.app/n8n/issue/PAY-1010/execution-deletion-in-queue-mode-not-complying-with-settings
This commit is contained in:
parent
ad04986ce7
commit
b7c5c7406f
|
@ -559,11 +559,8 @@ export class WorkflowRunner {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
let racingPromisesResult: JobResponse = {
|
|
||||||
success: false,
|
|
||||||
};
|
|
||||||
try {
|
try {
|
||||||
racingPromisesResult = await Promise.race(racingPromises);
|
await Promise.race(racingPromises);
|
||||||
if (clearWatchdogInterval !== undefined) {
|
if (clearWatchdogInterval !== undefined) {
|
||||||
clearWatchdogInterval();
|
clearWatchdogInterval();
|
||||||
}
|
}
|
||||||
|
@ -617,6 +614,7 @@ export class WorkflowRunner {
|
||||||
mode: fullExecutionData.mode,
|
mode: fullExecutionData.mode,
|
||||||
startedAt: fullExecutionData.startedAt,
|
startedAt: fullExecutionData.startedAt,
|
||||||
stoppedAt: fullExecutionData.stoppedAt,
|
stoppedAt: fullExecutionData.stoppedAt,
|
||||||
|
status: fullExecutionData.status,
|
||||||
} as IRun;
|
} as IRun;
|
||||||
|
|
||||||
if (executionHasPostExecutionPromises) {
|
if (executionHasPostExecutionPromises) {
|
||||||
|
@ -631,31 +629,6 @@ export class WorkflowRunner {
|
||||||
// Normally also static data should be supplied here but as it only used for sending
|
// Normally also static data should be supplied here but as it only used for sending
|
||||||
// data to editor-UI is not needed.
|
// data to editor-UI is not needed.
|
||||||
await hooks.executeHookFunctions('workflowExecuteAfter', [runData]);
|
await hooks.executeHookFunctions('workflowExecuteAfter', [runData]);
|
||||||
try {
|
|
||||||
// Check if this execution data has to be removed from database
|
|
||||||
// based on workflow settings.
|
|
||||||
const workflowSettings = data.workflowData.settings ?? {};
|
|
||||||
const saveDataErrorExecution =
|
|
||||||
workflowSettings.saveDataErrorExecution ?? config.getEnv('executions.saveDataOnError');
|
|
||||||
const saveDataSuccessExecution =
|
|
||||||
workflowSettings.saveDataSuccessExecution ??
|
|
||||||
config.getEnv('executions.saveDataOnSuccess');
|
|
||||||
|
|
||||||
const workflowDidSucceed = !racingPromisesResult.error;
|
|
||||||
if (
|
|
||||||
(workflowDidSucceed && saveDataSuccessExecution === 'none') ||
|
|
||||||
(!workflowDidSucceed && saveDataErrorExecution === 'none')
|
|
||||||
) {
|
|
||||||
await Container.get(ExecutionRepository).hardDelete({
|
|
||||||
workflowId: data.workflowData.id as string,
|
|
||||||
executionId,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
// eslint-disable-next-line id-denylist
|
|
||||||
} catch (err) {
|
|
||||||
// We don't want errors here to crash n8n. Just log and proceed.
|
|
||||||
console.log('Error removing saved execution from database. More details: ', err);
|
|
||||||
}
|
|
||||||
|
|
||||||
resolve(runData);
|
resolve(runData);
|
||||||
},
|
},
|
||||||
|
|
|
@ -10,8 +10,12 @@ import { Logger } from '@/Logger';
|
||||||
export function determineFinalExecutionStatus(runData: IRun): ExecutionStatus {
|
export function determineFinalExecutionStatus(runData: IRun): ExecutionStatus {
|
||||||
const workflowHasCrashed = runData.status === 'crashed';
|
const workflowHasCrashed = runData.status === 'crashed';
|
||||||
const workflowWasCanceled = runData.status === 'canceled';
|
const workflowWasCanceled = runData.status === 'canceled';
|
||||||
|
const workflowHasFailed = runData.status === 'failed';
|
||||||
const workflowDidSucceed =
|
const workflowDidSucceed =
|
||||||
!runData.data.resultData?.error && !workflowHasCrashed && !workflowWasCanceled;
|
!runData.data.resultData?.error &&
|
||||||
|
!workflowHasCrashed &&
|
||||||
|
!workflowWasCanceled &&
|
||||||
|
!workflowHasFailed;
|
||||||
let workflowStatusFinal: ExecutionStatus = workflowDidSucceed ? 'success' : 'failed';
|
let workflowStatusFinal: ExecutionStatus = workflowDidSucceed ? 'success' : 'failed';
|
||||||
if (workflowHasCrashed) workflowStatusFinal = 'crashed';
|
if (workflowHasCrashed) workflowStatusFinal = 'crashed';
|
||||||
if (workflowWasCanceled) workflowStatusFinal = 'canceled';
|
if (workflowWasCanceled) workflowStatusFinal = 'canceled';
|
||||||
|
|
Loading…
Reference in a new issue