do not even setup the nodeExecuteAfter hook for progress saving if the settings disable progress saving

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™ 2025-01-30 14:09:15 +01:00
parent 4471c0f066
commit 50b45cff3a
No known key found for this signature in database
4 changed files with 11 additions and 20 deletions

View file

@ -206,7 +206,7 @@ describe('Execution Lifecycle Hooks', () => {
const { hookFunctions } = hooks; const { hookFunctions } = hooks;
expect(hookFunctions.nodeExecuteBefore).toHaveLength(2); expect(hookFunctions.nodeExecuteBefore).toHaveLength(2);
expect(hookFunctions.nodeExecuteAfter).toHaveLength(3); expect(hookFunctions.nodeExecuteAfter).toHaveLength(2);
expect(hookFunctions.workflowExecuteBefore).toHaveLength(3); expect(hookFunctions.workflowExecuteBefore).toHaveLength(3);
expect(hookFunctions.workflowExecuteAfter).toHaveLength(5); expect(hookFunctions.workflowExecuteAfter).toHaveLength(5);
expect(hookFunctions.nodeFetchedData).toHaveLength(1); expect(hookFunctions.nodeFetchedData).toHaveLength(1);
@ -242,6 +242,8 @@ describe('Execution Lifecycle Hooks', () => {
workflowData.settings = { saveExecutionProgress: true }; workflowData.settings = { saveExecutionProgress: true };
hooks = createHooks(); hooks = createHooks();
expect(hooks.hookFunctions.nodeExecuteAfter).toHaveLength(3);
await hooks.executeHookFunctions('nodeExecuteAfter', [ await hooks.executeHookFunctions('nodeExecuteAfter', [
nodeName, nodeName,
taskData, taskData,
@ -258,6 +260,8 @@ describe('Execution Lifecycle Hooks', () => {
workflowData.settings = { saveExecutionProgress: false }; workflowData.settings = { saveExecutionProgress: false };
hooks = createHooks(); hooks = createHooks();
expect(hooks.hookFunctions.nodeExecuteAfter).toHaveLength(3);
await hooks.executeHookFunctions('nodeExecuteAfter', [ await hooks.executeHookFunctions('nodeExecuteAfter', [
nodeName, nodeName,
taskData, taskData,
@ -622,7 +626,7 @@ describe('Execution Lifecycle Hooks', () => {
const { hookFunctions } = hooks; const { hookFunctions } = hooks;
expect(hookFunctions.nodeExecuteBefore).toHaveLength(2); expect(hookFunctions.nodeExecuteBefore).toHaveLength(2);
expect(hookFunctions.nodeExecuteAfter).toHaveLength(3); expect(hookFunctions.nodeExecuteAfter).toHaveLength(2);
expect(hookFunctions.workflowExecuteBefore).toHaveLength(2); expect(hookFunctions.workflowExecuteBefore).toHaveLength(2);
expect(hookFunctions.workflowExecuteAfter).toHaveLength(4); expect(hookFunctions.workflowExecuteAfter).toHaveLength(4);
expect(hookFunctions.nodeFetchedData).toHaveLength(1); expect(hookFunctions.nodeFetchedData).toHaveLength(1);
@ -719,7 +723,7 @@ describe('Execution Lifecycle Hooks', () => {
const { hookFunctions } = hooks; const { hookFunctions } = hooks;
expect(hookFunctions.nodeExecuteBefore).toHaveLength(1); expect(hookFunctions.nodeExecuteBefore).toHaveLength(1);
expect(hookFunctions.nodeExecuteAfter).toHaveLength(2); expect(hookFunctions.nodeExecuteAfter).toHaveLength(1);
expect(hookFunctions.workflowExecuteBefore).toHaveLength(2); expect(hookFunctions.workflowExecuteBefore).toHaveLength(2);
expect(hookFunctions.workflowExecuteAfter).toHaveLength(4); expect(hookFunctions.workflowExecuteAfter).toHaveLength(4);
expect(hookFunctions.nodeFetchedData).toHaveLength(1); expect(hookFunctions.nodeFetchedData).toHaveLength(1);

View file

@ -25,20 +25,12 @@ const commonArgs: [string, string, string, ITaskData, IRunExecutionData, string]
'some-session-id', 'some-session-id',
]; ];
const commonSettings = { error: true, success: true, manual: true };
test('should ignore if save settings say so', async () => {
await saveExecutionProgress({ ...commonSettings, progress: false }, ...commonArgs);
expect(executionRepository.updateExistingExecution).not.toHaveBeenCalled();
});
test('should ignore on leftover async call', async () => { test('should ignore on leftover async call', async () => {
executionRepository.findSingleExecution.mockResolvedValue({ executionRepository.findSingleExecution.mockResolvedValue({
finished: true, finished: true,
} as IExecutionResponse); } as IExecutionResponse);
await saveExecutionProgress({ ...commonSettings, progress: true }, ...commonArgs); await saveExecutionProgress(...commonArgs);
expect(executionRepository.updateExistingExecution).not.toHaveBeenCalled(); expect(executionRepository.updateExistingExecution).not.toHaveBeenCalled();
}); });
@ -46,7 +38,7 @@ test('should ignore on leftover async call', async () => {
test('should update execution when saving progress is enabled', async () => { test('should update execution when saving progress is enabled', async () => {
executionRepository.findSingleExecution.mockResolvedValue({} as IExecutionResponse); executionRepository.findSingleExecution.mockResolvedValue({} as IExecutionResponse);
await saveExecutionProgress({ ...commonSettings, progress: true }, ...commonArgs); await saveExecutionProgress(...commonArgs);
expect(executionRepository.updateExistingExecution).toHaveBeenCalledWith('some-execution-id', { expect(executionRepository.updateExistingExecution).toHaveBeenCalledWith('some-execution-id', {
data: { data: {
@ -72,7 +64,7 @@ test('should report error on failure', async () => {
throw error; throw error;
}); });
await saveExecutionProgress({ ...commonSettings, progress: true }, ...commonArgs); await saveExecutionProgress(...commonArgs);
expect(executionRepository.updateExistingExecution).not.toHaveBeenCalled(); expect(executionRepository.updateExistingExecution).not.toHaveBeenCalled();
expect(errorReporter.error).toHaveBeenCalledWith(error); expect(errorReporter.error).toHaveBeenCalledWith(error);

View file

@ -213,6 +213,7 @@ function hookFunctionsExternalHooks(): IWorkflowExecuteHooks {
} }
function hookFunctionsSaveProgress(saveSettings: ExecutionSavingSettings): IWorkflowExecuteHooks { function hookFunctionsSaveProgress(saveSettings: ExecutionSavingSettings): IWorkflowExecuteHooks {
if (!saveSettings.progress) return {};
return { return {
nodeExecuteAfter: [ nodeExecuteAfter: [
async function ( async function (
@ -222,7 +223,6 @@ function hookFunctionsSaveProgress(saveSettings: ExecutionSavingSettings): IWork
executionData: IRunExecutionData, executionData: IRunExecutionData,
): Promise<void> { ): Promise<void> {
await saveExecutionProgress( await saveExecutionProgress(
saveSettings,
this.workflowData.id, this.workflowData.id,
this.executionId, this.executionId,
nodeName, nodeName,

View file

@ -4,10 +4,7 @@ import type { IRunExecutionData, ITaskData } from 'n8n-workflow';
import { ExecutionRepository } from '@/databases/repositories/execution.repository'; import { ExecutionRepository } from '@/databases/repositories/execution.repository';
import { type ExecutionSavingSettings } from './to-save-settings';
export async function saveExecutionProgress( export async function saveExecutionProgress(
saveSettings: ExecutionSavingSettings,
workflowId: string, workflowId: string,
executionId: string, executionId: string,
nodeName: string, nodeName: string,
@ -15,8 +12,6 @@ export async function saveExecutionProgress(
executionData: IRunExecutionData, executionData: IRunExecutionData,
pushRef?: string, pushRef?: string,
) { ) {
if (!saveSettings.progress) return;
const logger = Container.get(Logger); const logger = Container.get(Logger);
try { try {