diff --git a/packages/cli/src/WorkflowRunnerProcess.ts b/packages/cli/src/WorkflowRunnerProcess.ts index 0c631dc95a..528c92f471 100644 --- a/packages/cli/src/WorkflowRunnerProcess.ts +++ b/packages/cli/src/WorkflowRunnerProcess.ts @@ -29,6 +29,7 @@ export class WorkflowRunnerProcess { workflow: Workflow | undefined; workflowExecute: WorkflowExecute | undefined; + async runWorkflow(inputData: IWorkflowExecutionDataProcessWithExecution): Promise { this.data = inputData; let className: string; @@ -81,16 +82,30 @@ export class WorkflowRunnerProcess { } + /** + * Sends hook data to the parent process that it executes them + * + * @param {string} hook + * @param {any[]} parameters + * @memberof WorkflowRunnerProcess + */ sendHookToParentProcess(hook: string, parameters: any[]) { // tslint:disable-line:no-any - (process as unknown as ChildProcess).send({ - type: 'processHook', - data: { + try { + sendToParentProcess('processHook', { hook, parameters, - } as IProcessMessageDataHook, - } as IProcessMessage); + }); + } catch (error) { + // TODO: Add proper logging + console.error(`There was a problem sending hook: "${hook}"`); + console.error('Parameters:'); + console.error(parameters); + console.error('Error:'); + console.error(error); + } } + /** * Create a wrapper for hooks which simply forwards the data to * the parent process where they then can be executed with access @@ -169,18 +184,18 @@ process.on('message', async (message: IProcessMessage) => { process.exit(); } else if (message.type === 'stopExecution') { // The workflow execution should be stopped - let fullRunData: IRun; + let runData: IRun; if (workflowRunner.workflowExecute !== undefined) { // Workflow started already executing - fullRunData = workflowRunner.workflowExecute.getFullRunData(workflowRunner.startedAt); + runData = workflowRunner.workflowExecute.getFullRunData(workflowRunner.startedAt); // If there is any data send it to parent process await workflowRunner.workflowExecute.processSuccessExecution(workflowRunner.startedAt, workflowRunner.workflow!); } else { // Workflow did not get started yet - fullRunData = { + runData = { data: { resultData: { runData: {}, @@ -192,11 +207,11 @@ process.on('message', async (message: IProcessMessage) => { stoppedAt: new Date(), }; - workflowRunner.sendHookToParentProcess('workflowExecuteAfter', [fullRunData]); + workflowRunner.sendHookToParentProcess('workflowExecuteAfter', [runData]); } await sendToParentProcess('end', { - fullRunData, + runData, }); // Stop process