mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-26 05:04:05 -08:00
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import {
|
|
IWorkflowBase,
|
|
IWorkflowExecuteHooks,
|
|
IWorkflowHooksOptionalParameters,
|
|
WorkflowExecuteMode,
|
|
} from './Interfaces';
|
|
|
|
|
|
export class WorkflowHooks {
|
|
mode: WorkflowExecuteMode;
|
|
workflowData: IWorkflowBase;
|
|
executionId: string;
|
|
sessionId?: string;
|
|
retryOf?: string;
|
|
hookFunctions: IWorkflowExecuteHooks;
|
|
|
|
constructor(hookFunctions: IWorkflowExecuteHooks, mode: WorkflowExecuteMode, executionId: string, workflowData: IWorkflowBase, optionalParameters?: IWorkflowHooksOptionalParameters) {
|
|
optionalParameters = optionalParameters || {};
|
|
|
|
this.hookFunctions = hookFunctions;
|
|
this.mode = mode;
|
|
this.executionId = executionId;
|
|
this.workflowData = workflowData;
|
|
this.sessionId = optionalParameters.sessionId;
|
|
this.retryOf = optionalParameters.retryOf;
|
|
}
|
|
|
|
async executeHookFunctions(hookName: string, parameters: any[]) { // tslint:disable-line:no-any
|
|
if (this.hookFunctions[hookName] !== undefined && Array.isArray(this.hookFunctions[hookName])) {
|
|
for (const hookFunction of this.hookFunctions[hookName]!) {
|
|
await hookFunction.apply(this, parameters);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|