This commit is contained in:
Mutasem Aldmour 2024-11-12 11:57:37 +01:00
parent 893eb5c42d
commit 2fde595611
No known key found for this signature in database
GPG key ID: 3DFA8122BB7FD6B8

View file

@ -777,16 +777,48 @@ export async function executeWorkflow(
additionalData: IWorkflowExecuteAdditionalData,
options: ExecuteWorkflowOptions,
): Promise<ExecuteWorkflowData> {
const externalHooks = Container.get(ExternalHooks);
await externalHooks.init();
const nodeTypes = Container.get(NodeTypes);
const activeExecutions = Container.get(ActiveExecutions);
const workflowData =
options.loadedWorkflowData ??
(await getWorkflowData(workflowInfo, options.parentWorkflowId, options.parentWorkflowSettings));
const runData =
options.loadedRunData ??
(await getRunData(workflowData, options.inputData, options.startMetadata));
const executionId = await activeExecutions.add(runData);
const executionPromise = startExecution(
additionalData,
options,
executionId,
runData,
workflowData,
);
if (options.doNotWaitToFinish) {
return { executionId, data: [null] };
}
return await executionPromise;
}
async function startExecution(
additionalData: IWorkflowExecuteAdditionalData,
options: ExecuteWorkflowOptions,
executionId: string,
runData: IWorkflowExecutionDataProcess,
workflowData: IWorkflowBase,
): Promise<ExecuteWorkflowData> {
const externalHooks = Container.get(ExternalHooks);
await externalHooks.init();
const nodeTypes = Container.get(NodeTypes);
const activeExecutions = Container.get(ActiveExecutions);
const eventService = Container.get(EventService);
const executionRepository = Container.get(ExecutionRepository);
const workflowName = workflowData ? workflowData.name : undefined;
const workflow = new Workflow({
id: workflowData.id,
@ -799,46 +831,6 @@ export async function executeWorkflow(
settings: workflowData.settings,
});
const runData =
options.loadedRunData ??
(await getRunData(workflowData, options.inputData, options.startMetadata));
const executionId = await activeExecutions.add(runData);
// We wrap it in another promise that we can depending on the setting return
// the execution ID before the execution is finished
const executionPromise = startExecution(
additionalData,
options,
workflow,
executionId,
runData,
workflowData,
externalHooks,
);
if (options.doNotWaitToFinish) {
// todo check if not breaking change
return { executionId, data: [null] };
}
return await executionPromise;
}
// todo simplify
async function startExecution(
additionalData: IWorkflowExecuteAdditionalData,
options: ExecuteWorkflowOptions,
workflow: Workflow,
executionId: string,
runData: IWorkflowExecutionDataProcess,
workflowData: IWorkflowBase,
externalHooks: ExternalHooks,
): Promise<ExecuteWorkflowData> {
const eventService = Container.get(EventService);
const activeExecutions = Container.get(ActiveExecutions);
const executionRepository = Container.get(ExecutionRepository);
/**
* A subworkflow execution in queue mode is not enqueued, but rather runs in the
* same worker process as the parent execution. Hence ensure the subworkflow