import type { PublicMethodsOf } from '@kbn/utility-types' ; import type { Logger , KibanaRequest , ISavedObjectsRepository , IBasePath , ExecutionContextStart , } from '../../../../../src/core/server' ; import { RunContext } from '../../../task_manager/server' ; import { EncryptedSavedObjectsClient } from '../../../encrypted_saved_objects/server' ; import { PluginStartContract as ActionsPluginStartContract } from '../../../actions/server' ; import { AlertTypeParams , RuleTypeRegistry , GetServicesFunction , SpaceIdToNamespaceFunction , AlertTypeState , AlertInstanceState , AlertInstanceContext , } from '../types' ; import { TaskRunner } from './task_runner' ; import { IEventLogger } from '../../../event_log/server' ; import { RulesClient } from '../rules_client' ; import { NormalizedRuleType } from '../rule_type_registry' ; export interface TaskRunnerContext { logger : Logger ; getServices : GetServicesFunction ; getRulesClientWithRequest ( request ) : PublicMethodsOf < RulesClient > ; actionsPlugin : ActionsPluginStartContract ; eventLogger : IEventLogger ; encryptedSavedObjectsClient : EncryptedSavedObjectsClient ; executionContext : ExecutionContextStart ; spaceIdToNamespace : SpaceIdToNamespaceFunction ; basePathService : IBasePath ; internalSavedObjectsRepository : ISavedObjectsRepository ; ruleTypeRegistry : RuleTypeRegistry ; kibanaBaseUrl : string | undefined ; supportsEphemeralTasks : boolean ; maxEphemeralActionsPerRule : number ; cancelAlertsOnRuleTimeout : boolean ; } export class TaskRunnerFactory { private isInitialized = false ; private taskRunnerContext ? : TaskRunnerContext ; public initialize ( taskRunnerContext ) { if ( this . isInitialized ) { throw new Error ( 'TaskRunnerFactory already initialized' ) ; } this . isInitialized = true ; this . taskRunnerContext = taskRunnerContext ; } public create < Params extends AlertTypeParams , ExtractedParams extends AlertTypeParams , State extends AlertTypeState , InstanceState extends AlertInstanceState , InstanceContext extends AlertInstanceContext , ActionGroupIds extends string , RecoveryActionGroupId extends string > ( ruleType , { taskInstance } ) { if ( ! this . isInitialized ) { throw new Error ( 'TaskRunnerFactory not initialized' ) ; } return new TaskRunner < Params , ExtractedParams , State , InstanceState , InstanceContext , ActionGroupIds , RecoveryActionGroupId > ( ruleType , taskInstance , this . taskRunnerContext ! ) ; } }