diff --git a/packages/cli/src/workflow-execute-additional-data.ts b/packages/cli/src/workflow-execute-additional-data.ts index 814085b68b..db9e5d934a 100644 --- a/packages/cli/src/workflow-execute-additional-data.ts +++ b/packages/cli/src/workflow-execute-additional-data.ts @@ -777,16 +777,48 @@ export async function executeWorkflow( additionalData: IWorkflowExecuteAdditionalData, options: ExecuteWorkflowOptions, ): Promise { - 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 { + 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 { - 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