mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
refactor(core): Refactor execution post-execute promises (no-changelog) (#10809)
Co-authored-by: Danny Martini <danny@n8n.io>
This commit is contained in:
committed by
GitHub
parent
521bbfeee5
commit
67fb6d6fdd
@@ -26,7 +26,6 @@ import { ActiveExecutions } from '@/active-executions';
|
||||
import config from '@/config';
|
||||
import { ExecutionRepository } from '@/databases/repositories/execution.repository';
|
||||
import { ExternalHooks } from '@/external-hooks';
|
||||
import type { IExecutionResponse } from '@/interfaces';
|
||||
import { Logger } from '@/logger';
|
||||
import { NodeTypes } from '@/node-types';
|
||||
import type { ScalingService } from '@/scaling/scaling.service';
|
||||
@@ -102,7 +101,7 @@ export class WorkflowRunner {
|
||||
|
||||
// Remove from active execution with empty data. That will
|
||||
// set the execution to failed.
|
||||
this.activeExecutions.remove(executionId, fullRunData);
|
||||
this.activeExecutions.finalizeExecution(executionId, fullRunData);
|
||||
|
||||
if (hooks) {
|
||||
await hooks.executeHookFunctions('workflowExecuteAfter', [fullRunData]);
|
||||
@@ -132,7 +131,7 @@ export class WorkflowRunner {
|
||||
await workflowHooks.executeHookFunctions('workflowExecuteBefore', []);
|
||||
await workflowHooks.executeHookFunctions('workflowExecuteAfter', [runData]);
|
||||
responsePromise?.reject(error);
|
||||
this.activeExecutions.remove(executionId);
|
||||
this.activeExecutions.finalizeExecution(executionId);
|
||||
return executionId;
|
||||
}
|
||||
|
||||
@@ -336,7 +335,7 @@ export class WorkflowRunner {
|
||||
fullRunData.finished = false;
|
||||
}
|
||||
fullRunData.status = this.activeExecutions.getStatus(executionId);
|
||||
this.activeExecutions.remove(executionId, fullRunData);
|
||||
this.activeExecutions.finalizeExecution(executionId, fullRunData);
|
||||
})
|
||||
.catch(
|
||||
async (error) =>
|
||||
@@ -505,45 +504,24 @@ export class WorkflowRunner {
|
||||
reject(error);
|
||||
}
|
||||
|
||||
// optimization: only pull and unflatten execution data from the Db when it is needed
|
||||
const executionHasPostExecutionPromises =
|
||||
this.activeExecutions.getPostExecutePromiseCount(executionId) > 0;
|
||||
|
||||
if (executionHasPostExecutionPromises) {
|
||||
this.logger.debug(
|
||||
`Reading execution data for execution ${executionId} from db for PostExecutionPromise.`,
|
||||
);
|
||||
} else {
|
||||
this.logger.debug(
|
||||
`Skipping execution data for execution ${executionId} since there are no PostExecutionPromise.`,
|
||||
);
|
||||
}
|
||||
|
||||
const fullExecutionData = await this.executionRepository.findSingleExecution(executionId, {
|
||||
includeData: executionHasPostExecutionPromises,
|
||||
unflattenData: executionHasPostExecutionPromises,
|
||||
includeData: true,
|
||||
unflattenData: true,
|
||||
});
|
||||
if (!fullExecutionData) {
|
||||
return reject(new Error(`Could not find execution with id "${executionId}"`));
|
||||
}
|
||||
|
||||
const runData: IRun = {
|
||||
data: {},
|
||||
finished: fullExecutionData.finished,
|
||||
mode: fullExecutionData.mode,
|
||||
startedAt: fullExecutionData.startedAt,
|
||||
stoppedAt: fullExecutionData.stoppedAt,
|
||||
status: fullExecutionData.status,
|
||||
} as IRun;
|
||||
data: fullExecutionData.data,
|
||||
};
|
||||
|
||||
if (executionHasPostExecutionPromises) {
|
||||
runData.data = (fullExecutionData as IExecutionResponse).data;
|
||||
}
|
||||
|
||||
// NOTE: due to the optimization of not loading the execution data from the db when no post execution promises are present,
|
||||
// the execution data in runData.data MAY not be available here.
|
||||
// This means that any function expecting with runData has to check if the runData.data defined from this point
|
||||
this.activeExecutions.remove(executionId, runData);
|
||||
this.activeExecutions.finalizeExecution(executionId, runData);
|
||||
|
||||
// Normally also static data should be supplied here but as it only used for sending
|
||||
// data to editor-UI is not needed.
|
||||
|
||||
Reference in New Issue
Block a user