import type { SavedObjectsServiceSetup , SavedObjectsTypeMappingDefinition } from 'kibana/server' ; import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey' ; import mappings from './mappings.json' ; import { getMigrations } from './migrations' ; import { TaskManagerConfig } from '../config.js' ; import { getOldestIdleActionTask } from '../queries/oldest_idle_action_task' ; import { TASK_MANAGER_INDEX } from '../constants' ; export function setupSavedObjects ( savedObjects , config ) { savedObjects . registerType ( { name : 'task' , namespaceType : 'agnostic' , hidden : true , convertToAliasScript : `ctx._id = ctx._source.type + ':' + ctx._id; ctx._source.remove("kibana")` , mappings : mappings . task as SavedObjectsTypeMappingDefinition , migrations : getMigrations ( ) , indexPattern : TASK_MANAGER_INDEX , excludeOnUpgrade : async ( { readonlyEsClient } ) => { const oldestNeededActionParams = await getOldestIdleActionTask ( readonlyEsClient , TASK_MANAGER_INDEX ) ; return { bool : { must : [ { terms : { 'task.taskType' : [ 'actions:.email' , 'actions:.index' , 'actions:.pagerduty' , 'actions:.swimlane' , 'actions:.server-log' , 'actions:.slack' , 'actions:.webhook' , 'actions:.servicenow' , 'actions:.servicenow-sir' , 'actions:.jira' , 'actions:.resilient' , 'actions:.teams' , ] , } , } , { term : { type : 'task' } , } , { term : { 'task.status' : 'failed' } , } , { range : { 'task.runAt' : { lt : oldestNeededActionParams , } , } , } , ] , } , } as estypes . QueryDslQueryContainer ; } , } ) ; }