Add hook which gets called after a workflow execution

This commit is contained in:
Jan Oberhauser 2020-10-20 19:01:40 +02:00
parent cf31ec722c
commit 70435b582a
4 changed files with 23 additions and 2 deletions

View file

@ -64,6 +64,10 @@ class ExternalHooksClass implements IExternalHooksClass {
}
}
exists(hookName: string): boolean {
return !!this.externalHooks[hookName];
}
}

View file

@ -3,6 +3,7 @@ import { get } from 'lodash';
import {
ActiveExecutions,
ExternalHooks,
GenericHelpers,
IExecutionDb,
IResponseCallbackData,

View file

@ -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);

View file

@ -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;
}