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
|
|
|
|
2024-04-03 04:43:14 -07:00
|
|
|
pushRef?: 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;
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
hookFunctions: IWorkflowExecuteHooks,
|
|
|
|
mode: WorkflowExecuteMode,
|
|
|
|
executionId: string,
|
|
|
|
workflowData: IWorkflowBase,
|
|
|
|
optionalParameters?: IWorkflowHooksOptionalParameters,
|
|
|
|
) {
|
2023-07-31 02:00:48 -07:00
|
|
|
// eslint-disable-next-line @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;
|
2024-04-03 04:43:14 -07:00
|
|
|
this.pushRef = optionalParameters.pushRef;
|
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
|
|
|
}
|
|
|
|
|
2023-07-31 02:00:48 -07:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2019-12-19 14:07:55 -08:00
|
|
|
async executeHookFunctions(hookName: string, parameters: any[]) {
|
2024-06-24 08:49:59 -07:00
|
|
|
const hooks = this.hookFunctions[hookName];
|
|
|
|
if (hooks !== undefined && Array.isArray(hooks)) {
|
|
|
|
for (const hookFunction of hooks) {
|
2020-11-13 14:31:27 -08:00
|
|
|
await hookFunction.apply(this, parameters);
|
2019-12-19 14:07:55 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|