| | import { Logger } from '@n8n/backend-common'; |
| | import { ExecutionRepository } from '@n8n/db'; |
| | import { Container } from '@n8n/di'; |
| | import { ErrorReporter } from 'n8n-core'; |
| | import type { IRunExecutionData, ITaskData } from 'n8n-workflow'; |
| |
|
| | export async function saveExecutionProgress( |
| | workflowId: string, |
| | executionId: string, |
| | nodeName: string, |
| | data: ITaskData, |
| | executionData: IRunExecutionData, |
| | ) { |
| | const logger = Container.get(Logger); |
| | const executionRepository = Container.get(ExecutionRepository); |
| | const errorReporter = Container.get(ErrorReporter); |
| |
|
| | try { |
| | logger.debug(`Save execution progress to database for execution ID ${executionId} `, { |
| | executionId, |
| | nodeName, |
| | }); |
| |
|
| | const fullExecutionData = await executionRepository.findSingleExecution(executionId, { |
| | includeData: true, |
| | unflattenData: true, |
| | }); |
| |
|
| | if (!fullExecutionData) { |
| | |
| | |
| | return; |
| | } |
| |
|
| | if (fullExecutionData.finished) { |
| | |
| | |
| | |
| | return; |
| | } |
| |
|
| | fullExecutionData.data ??= { |
| | startData: {}, |
| | resultData: { |
| | runData: {}, |
| | }, |
| | executionData: { |
| | contextData: {}, |
| | metadata: {}, |
| | nodeExecutionStack: [], |
| | waitingExecution: {}, |
| | waitingExecutionSource: {}, |
| | }, |
| | }; |
| |
|
| | const { runData } = fullExecutionData.data.resultData; |
| | (runData[nodeName] ??= []).push(data); |
| |
|
| | fullExecutionData.data.executionData = executionData.executionData; |
| |
|
| | |
| | fullExecutionData.data.resultData.lastNodeExecuted = nodeName; |
| |
|
| | fullExecutionData.status = 'running'; |
| |
|
| | await executionRepository.updateExistingExecution(executionId, fullExecutionData); |
| | } catch (e) { |
| | const error = e instanceof Error ? e : new Error(`${e}`); |
| |
|
| | errorReporter.error(error); |
| | |
| | |
| | |
| |
|
| | |
| | logger.error( |
| | `Failed saving execution progress to database for execution ID ${executionId} (hookFunctionsSaveProgress, nodeExecuteAfter)`, |
| | { error, executionId, workflowId }, |
| | ); |
| | } |
| | } |
| |
|