diff --git a/packages/cli/src/ExternalHooks.ts b/packages/cli/src/ExternalHooks.ts index 355415158a..d419b6fd6c 100644 --- a/packages/cli/src/ExternalHooks.ts +++ b/packages/cli/src/ExternalHooks.ts @@ -64,6 +64,10 @@ class ExternalHooksClass implements IExternalHooksClass { } } + exists(hookName: string): boolean { + return !!this.externalHooks[hookName]; + } + } diff --git a/packages/cli/src/WebhookHelpers.ts b/packages/cli/src/WebhookHelpers.ts index a1b77c7975..5093019d85 100644 --- a/packages/cli/src/WebhookHelpers.ts +++ b/packages/cli/src/WebhookHelpers.ts @@ -3,6 +3,7 @@ import { get } from 'lodash'; import { ActiveExecutions, + ExternalHooks, GenericHelpers, IExecutionDb, IResponseCallbackData, diff --git a/packages/cli/src/WorkflowExecuteAdditionalData.ts b/packages/cli/src/WorkflowExecuteAdditionalData.ts index 4230e79f58..4ec59e14ad 100644 --- a/packages/cli/src/WorkflowExecuteAdditionalData.ts +++ b/packages/cli/src/WorkflowExecuteAdditionalData.ts @@ -406,6 +406,8 @@ export async function executeWorkflow(workflowInfo: IExecuteWorkflowInfo, additi const workflowExecute = new WorkflowExecute(additionalDataIntegrated, mode, runExecutionData); const data = await workflowExecute.processRunExecutionData(workflow); + await externalHooks.run('workflow.postExecute', [data, workflowData]); + if (data.finished === true) { // Workflow did finish successfully const returnData = WorkflowHelpers.getDataLastExecutedNodeData(data); diff --git a/packages/cli/src/WorkflowRunner.ts b/packages/cli/src/WorkflowRunner.ts index f0171322a5..5e45a91221 100644 --- a/packages/cli/src/WorkflowRunner.ts +++ b/packages/cli/src/WorkflowRunner.ts @@ -104,11 +104,25 @@ export class WorkflowRunner { await externalHooks.run('workflow.execute', [data.workflowData, data.executionMode]); const executionsProcess = config.get('executions.process') as string; + + let executionId: string; if (executionsProcess === 'main') { - return this.runMainProcess(data, loadStaticData); + executionId = await this.runMainProcess(data, loadStaticData); + } else { + executionId = await this.runSubprocess(data, loadStaticData); } - return this.runSubprocess(data, loadStaticData); + if (externalHooks.exists('workflow.postExecute')) { + this.activeExecutions.getPostExecutePromise(executionId) + .then(async (executionData) => { + await externalHooks.run('workflow.postExecute', [executionData, data.workflowData]); + }) + .catch(error => { + console.error('There was a problem running hook "workflow.postExecute"', error); + }); + } + + return executionId; }