mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 12:44:07 -08:00
⚡ Add hook which gets called after a workflow execution
This commit is contained in:
parent
cf31ec722c
commit
70435b582a
|
@ -64,6 +64,10 @@ class ExternalHooksClass implements IExternalHooksClass {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exists(hookName: string): boolean {
|
||||||
|
return !!this.externalHooks[hookName];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ import { get } from 'lodash';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
ActiveExecutions,
|
ActiveExecutions,
|
||||||
|
ExternalHooks,
|
||||||
GenericHelpers,
|
GenericHelpers,
|
||||||
IExecutionDb,
|
IExecutionDb,
|
||||||
IResponseCallbackData,
|
IResponseCallbackData,
|
||||||
|
|
|
@ -406,6 +406,8 @@ export async function executeWorkflow(workflowInfo: IExecuteWorkflowInfo, additi
|
||||||
const workflowExecute = new WorkflowExecute(additionalDataIntegrated, mode, runExecutionData);
|
const workflowExecute = new WorkflowExecute(additionalDataIntegrated, mode, runExecutionData);
|
||||||
const data = await workflowExecute.processRunExecutionData(workflow);
|
const data = await workflowExecute.processRunExecutionData(workflow);
|
||||||
|
|
||||||
|
await externalHooks.run('workflow.postExecute', [data, workflowData]);
|
||||||
|
|
||||||
if (data.finished === true) {
|
if (data.finished === true) {
|
||||||
// Workflow did finish successfully
|
// Workflow did finish successfully
|
||||||
const returnData = WorkflowHelpers.getDataLastExecutedNodeData(data);
|
const returnData = WorkflowHelpers.getDataLastExecutedNodeData(data);
|
||||||
|
|
|
@ -104,11 +104,25 @@ export class WorkflowRunner {
|
||||||
await externalHooks.run('workflow.execute', [data.workflowData, data.executionMode]);
|
await externalHooks.run('workflow.execute', [data.workflowData, data.executionMode]);
|
||||||
|
|
||||||
const executionsProcess = config.get('executions.process') as string;
|
const executionsProcess = config.get('executions.process') as string;
|
||||||
|
|
||||||
|
let executionId: string;
|
||||||
if (executionsProcess === 'main') {
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue