From 51bbb2b899db1ed70f11052ec3ddc634069a3100 Mon Sep 17 00:00:00 2001 From: James Gowdy Date: Tue, 10 Nov 2020 19:10:27 +0000 Subject: [PATCH] adding ids to saved objects --- .../ml/server/saved_objects/service.ts | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/x-pack/plugins/ml/server/saved_objects/service.ts b/x-pack/plugins/ml/server/saved_objects/service.ts index cc0b182585ac4..a2453b9ab3fa1 100644 --- a/x-pack/plugins/ml/server/saved_objects/service.ts +++ b/x-pack/plugins/ml/server/saved_objects/service.ts @@ -58,17 +58,15 @@ export function jobSavedObjectServiceFactory( async function _createJob(jobType: JobType, jobId: string, datafeedId?: string) { await isMlReady(); - try { - await _deleteJob(jobType, jobId); - } catch (error) { - // fail silently - // the job object may or may not already exist, we'll overwrite it anyway. - } - await savedObjectsClient.create(ML_SAVED_OBJECT_TYPE, { - job_id: jobId, - datafeed_id: datafeedId ?? null, - type: jobType, - }); + await savedObjectsClient.create( + ML_SAVED_OBJECT_TYPE, + { + job_id: jobId, + datafeed_id: datafeedId ?? null, + type: jobType, + }, + { id: jobId, overwrite: true } + ); } async function _bulkCreateJobs(jobs: JobObject[], namespaces?: string[]) { @@ -76,6 +74,7 @@ export function jobSavedObjectServiceFactory( return await savedObjectsClient.bulkCreate( jobs.map((j) => ({ type: ML_SAVED_OBJECT_TYPE, + id: j.job_id, attributes: j, initialNamespaces: namespaces, }))