mirror of
https://github.com/n8n-io/n8n.git
synced 2025-02-02 07:01:30 -08:00
fix(core): Keep in-memory execution status in-sync with the DB (no-changelog) (#11843)
This commit is contained in:
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);
|
const saveSettings = toSaveSettings(this.workflowData.settings);
|
||||||
|
|
||||||
if (isManualMode && !saveSettings.manual && !fullRunData.waitTill) {
|
if (isManualMode && !saveSettings.manual && !fullRunData.waitTill) {
|
||||||
|
@ -427,7 +430,6 @@ function hookFunctionsSave(): IWorkflowExecuteHooks {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const executionStatus = determineFinalExecutionStatus(fullRunData);
|
|
||||||
const shouldNotSave =
|
const shouldNotSave =
|
||||||
(executionStatus === 'success' && !saveSettings.success) ||
|
(executionStatus === 'success' && !saveSettings.success) ||
|
||||||
(executionStatus !== 'success' && !saveSettings.error);
|
(executionStatus !== 'success' && !saveSettings.error);
|
||||||
|
@ -570,6 +572,7 @@ function hookFunctionsSaveWorker(): IWorkflowExecuteHooks {
|
||||||
}
|
}
|
||||||
|
|
||||||
const workflowStatusFinal = determineFinalExecutionStatus(fullRunData);
|
const workflowStatusFinal = determineFinalExecutionStatus(fullRunData);
|
||||||
|
fullRunData.status = workflowStatusFinal;
|
||||||
|
|
||||||
if (workflowStatusFinal !== 'success' && workflowStatusFinal !== 'waiting') {
|
if (workflowStatusFinal !== 'success' && workflowStatusFinal !== 'waiting') {
|
||||||
executeErrorWorkflow(
|
executeErrorWorkflow(
|
||||||
|
@ -1115,6 +1118,8 @@ export function getWorkflowHooksWorkerMain(
|
||||||
if (!fullRunData.finished) return;
|
if (!fullRunData.finished) return;
|
||||||
|
|
||||||
const executionStatus = determineFinalExecutionStatus(fullRunData);
|
const executionStatus = determineFinalExecutionStatus(fullRunData);
|
||||||
|
fullRunData.status = executionStatus;
|
||||||
|
|
||||||
const saveSettings = toSaveSettings(this.workflowData.settings);
|
const saveSettings = toSaveSettings(this.workflowData.settings);
|
||||||
|
|
||||||
const shouldNotSave =
|
const shouldNotSave =
|
||||||
|
|
Loading…
Reference in a new issue