diff --git a/x-pack/plugins/alerts/server/alerts_client/alerts_client.ts b/x-pack/plugins/alerts/server/alerts_client/alerts_client.ts index e21fee4ce3d61..7d33a50c906a2 100644 --- a/x-pack/plugins/alerts/server/alerts_client/alerts_client.ts +++ b/x-pack/plugins/alerts/server/alerts_client/alerts_client.ts @@ -41,9 +41,8 @@ import { InvalidateAPIKeyResult as SecurityPluginInvalidateAPIKeyResult, } from '../../../security/server'; import { EncryptedSavedObjectsClient } from '../../../encrypted_saved_objects/server'; -import { TaskManagerStartContract } from '../../../task_manager/server'; +import { TaskManagerStartContract, deleteTaskIfItExists } from '../../../task_manager/server'; import { taskInstanceToAlertTaskInstance } from '../task_runner/alert_task_instance'; -import { deleteTaskIfItExists } from '../lib/delete_task_if_it_exists'; import { RegistryAlertType, UntypedNormalizedAlertType } from '../alert_type_registry'; import { AlertsAuthorization, WriteOperations, ReadOperations } from '../authorization'; import { IEventLogClient } from '../../../../plugins/event_log/server'; diff --git a/x-pack/plugins/data_enhanced/server/search/session/monitoring_task.ts b/x-pack/plugins/data_enhanced/server/search/session/monitoring_task.ts index f5e0218f9c0a2..e3c8d06c0c671 100644 --- a/x-pack/plugins/data_enhanced/server/search/session/monitoring_task.ts +++ b/x-pack/plugins/data_enhanced/server/search/session/monitoring_task.ts @@ -8,6 +8,7 @@ import { TaskManagerSetupContract, TaskManagerStartContract, RunContext, + deleteTaskIfItExists, } from '../../../../task_manager/server'; import { checkRunningSessions } from './check_running_sessions'; import { CoreSetup, SavedObjectsClient, Logger } from '../../../../../../src/core/server'; @@ -56,10 +57,7 @@ export async function scheduleSearchSessionsTasks( taskManager: TaskManagerStartContract, logger: Logger ) { - try { - // delete previous task - await taskManager.remove(SEARCH_SESSIONS_TASK_ID); - } catch (e) {} // eslint-disable-line no-empty + await deleteTaskIfItExists(taskManager, SEARCH_SESSIONS_TASK_ID); try { await taskManager.ensureScheduled({ diff --git a/x-pack/plugins/task_manager/server/index.ts b/x-pack/plugins/task_manager/server/index.ts index 1696a3ec69c05..5eb1f1e19f877 100644 --- a/x-pack/plugins/task_manager/server/index.ts +++ b/x-pack/plugins/task_manager/server/index.ts @@ -20,6 +20,7 @@ export { } from './task'; export { isUnrecoverableError, throwUnrecoverableError } from './task_running'; +export { deleteTaskIfItExists } from './lib/delete_task_if_it_exists'; export { TaskManagerPlugin as TaskManager, diff --git a/x-pack/plugins/alerts/server/lib/delete_task_if_it_exists.test.ts b/x-pack/plugins/task_manager/server/lib/delete_task_if_it_exists.test.ts similarity index 100% rename from x-pack/plugins/alerts/server/lib/delete_task_if_it_exists.test.ts rename to x-pack/plugins/task_manager/server/lib/delete_task_if_it_exists.test.ts diff --git a/x-pack/plugins/alerts/server/lib/delete_task_if_it_exists.ts b/x-pack/plugins/task_manager/server/lib/delete_task_if_it_exists.ts similarity index 88% rename from x-pack/plugins/alerts/server/lib/delete_task_if_it_exists.ts rename to x-pack/plugins/task_manager/server/lib/delete_task_if_it_exists.ts index 53bb1b5cb5d53..08d93f63c083a 100644 --- a/x-pack/plugins/alerts/server/lib/delete_task_if_it_exists.ts +++ b/x-pack/plugins/task_manager/server/lib/delete_task_if_it_exists.ts @@ -3,7 +3,7 @@ * or more contributor license agreements. Licensed under the Elastic License; * you may not use this file except in compliance with the Elastic License. */ -import { TaskManagerStartContract } from '../../../task_manager/server'; +import { TaskManagerStartContract } from '../'; import { SavedObjectsErrorHelpers } from '../../../../../src/core/server'; export async function deleteTaskIfItExists(taskManager: TaskManagerStartContract, taskId: string) {