2023-01-27 05:56:56 -08:00
|
|
|
import type {
|
2019-12-19 14:07:55 -08:00
|
|
|
IWorkflowBase,
|
|
|
|
IWorkflowExecuteHooks,
|
|
|
|
IWorkflowHooksOptionalParameters,
|
|
|
|
WorkflowExecuteMode,
|
|
|
|
} from './Interfaces';
|
|
|
|
|
|
|
|
export class WorkflowHooks {
|
|
|
|
mode: WorkflowExecuteMode;
|
2021-08-29 11:58:11 -07:00
|
|
|
|
2019-12-19 14:07:55 -08:00
|
|
|
workflowData: IWorkflowBase;
|
2021-08-29 11:58:11 -07:00
|
|
|
|
2019-12-19 14:07:55 -08:00
|
|
|
executionId: string;
|
2021-08-29 11:58:11 -07:00
|
|
|
|
2019-12-19 14:07:55 -08:00
|
|
|
sessionId?: string;
|
2021-08-29 11:58:11 -07:00
|
|
|
|
2019-12-19 14:07:55 -08:00
|
|
|
retryOf?: string;
|
2021-08-29 11:58:11 -07:00
|
|
|
|
2019-12-19 14:07:55 -08:00
|
|
|
hookFunctions: IWorkflowExecuteHooks;
|
|
|
|
|
2021-08-29 11:58:11 -07:00
|
|
|
constructor(
|
|
|
|
hookFunctions: IWorkflowExecuteHooks,
|
|
|
|
mode: WorkflowExecuteMode,
|
|
|
|
executionId: string,
|
|
|
|
workflowData: IWorkflowBase,
|
|
|
|
optionalParameters?: IWorkflowHooksOptionalParameters,
|
|
|
|
) {
|
|
|
|
// eslint-disable-next-line no-param-reassign, @typescript-eslint/prefer-nullish-coalescing
|
2019-12-19 14:07:55 -08:00
|
|
|
optionalParameters = optionalParameters || {};
|
|
|
|
|
|
|
|
this.hookFunctions = hookFunctions;
|
|
|
|
this.mode = mode;
|
|
|
|
this.executionId = executionId;
|
|
|
|
this.workflowData = workflowData;
|
|
|
|
this.sessionId = optionalParameters.sessionId;
|
2023-04-06 04:02:46 -07:00
|
|
|
// retryOf might be `null` from TypeORM
|
|
|
|
this.retryOf = optionalParameters.retryOf ?? undefined;
|
2019-12-19 14:07:55 -08:00
|
|
|
}
|
|
|
|
|
2021-08-29 11:58:11 -07:00
|
|
|
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-explicit-any
|
|
|
|
async executeHookFunctions(hookName: string, parameters: any[]) {
|
2019-12-19 14:07:55 -08:00
|
|
|
if (this.hookFunctions[hookName] !== undefined && Array.isArray(this.hookFunctions[hookName])) {
|
2021-08-29 11:58:11 -07:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion, no-restricted-syntax
|
2019-12-19 14:07:55 -08:00
|
|
|
for (const hookFunction of this.hookFunctions[hookName]!) {
|
2021-08-29 11:58:11 -07:00
|
|
|
// eslint-disable-next-line no-await-in-loop
|
2020-11-13 14:31:27 -08:00
|
|
|
await hookFunction.apply(this, parameters);
|
2019-12-19 14:07:55 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|