mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-16 17:46:45 +00:00
fix(core): Keep in-memory execution status in-sync with the DB (no-changelog) (#11843)
This commit is contained in:
committed by
GitHub
parent
96b95ef5e5
commit
13cc5abb7f
@@ -0,0 +1,37 @@
|
||||
import { mock } from 'jest-mock-extended';
|
||||
import type { IRun } from 'n8n-workflow';
|
||||
import { NodeOperationError } from 'n8n-workflow';
|
||||
|
||||
import { determineFinalExecutionStatus } from '../shared-hook-functions';
|
||||
|
||||
describe('determineFinalExecutionStatus', () => {
|
||||
describe('When waitTill is not set', () => {
|
||||
test.each(['canceled', 'crashed', 'error', 'success'])('should return "%s"', (status) => {
|
||||
const runData = { status, data: {} } as IRun;
|
||||
expect(determineFinalExecutionStatus(runData)).toBe(status);
|
||||
});
|
||||
});
|
||||
|
||||
it('should return "error" when resultData.error exists', () => {
|
||||
const runData = {
|
||||
status: 'running',
|
||||
data: {
|
||||
resultData: {
|
||||
error: new NodeOperationError(mock(), 'An error occurred'),
|
||||
},
|
||||
},
|
||||
} as IRun;
|
||||
|
||||
expect(determineFinalExecutionStatus(runData)).toBe('error');
|
||||
});
|
||||
|
||||
it('should return "waiting" when waitTill is defined', () => {
|
||||
const runData = {
|
||||
status: 'running',
|
||||
data: {},
|
||||
waitTill: new Date('2022-01-01T00:00:00'),
|
||||
} as IRun;
|
||||
|
||||
expect(determineFinalExecutionStatus(runData)).toBe('waiting');
|
||||
});
|
||||
});
|
||||
@@ -410,6 +410,9 @@ function hookFunctionsSave(): IWorkflowExecuteHooks {
|
||||
}
|
||||
}
|
||||
|
||||
const executionStatus = determineFinalExecutionStatus(fullRunData);
|
||||
fullRunData.status = executionStatus;
|
||||
|
||||
const saveSettings = toSaveSettings(this.workflowData.settings);
|
||||
|
||||
if (isManualMode && !saveSettings.manual && !fullRunData.waitTill) {
|
||||
@@ -427,7 +430,6 @@ function hookFunctionsSave(): IWorkflowExecuteHooks {
|
||||
return;
|
||||
}
|
||||
|
||||
const executionStatus = determineFinalExecutionStatus(fullRunData);
|
||||
const shouldNotSave =
|
||||
(executionStatus === 'success' && !saveSettings.success) ||
|
||||
(executionStatus !== 'success' && !saveSettings.error);
|
||||
@@ -570,6 +572,7 @@ function hookFunctionsSaveWorker(): IWorkflowExecuteHooks {
|
||||
}
|
||||
|
||||
const workflowStatusFinal = determineFinalExecutionStatus(fullRunData);
|
||||
fullRunData.status = workflowStatusFinal;
|
||||
|
||||
if (workflowStatusFinal !== 'success' && workflowStatusFinal !== 'waiting') {
|
||||
executeErrorWorkflow(
|
||||
@@ -1115,6 +1118,8 @@ export function getWorkflowHooksWorkerMain(
|
||||
if (!fullRunData.finished) return;
|
||||
|
||||
const executionStatus = determineFinalExecutionStatus(fullRunData);
|
||||
fullRunData.status = executionStatus;
|
||||
|
||||
const saveSettings = toSaveSettings(this.workflowData.settings);
|
||||
|
||||
const shouldNotSave =
|
||||
|
||||
Reference in New Issue
Block a user