Skip to content

Commit 51bbb2b

Browse files
committed
adding ids to saved objects
1 parent b81496e commit 51bbb2b

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

x-pack/plugins/ml/server/saved_objects/service.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,24 +58,23 @@ export function jobSavedObjectServiceFactory(
5858

5959
async function _createJob(jobType: JobType, jobId: string, datafeedId?: string) {
6060
await isMlReady();
61-
try {
62-
await _deleteJob(jobType, jobId);
63-
} catch (error) {
64-
// fail silently
65-
// the job object may or may not already exist, we'll overwrite it anyway.
66-
}
67-
await savedObjectsClient.create<JobObject>(ML_SAVED_OBJECT_TYPE, {
68-
job_id: jobId,
69-
datafeed_id: datafeedId ?? null,
70-
type: jobType,
71-
});
61+
await savedObjectsClient.create<JobObject>(
62+
ML_SAVED_OBJECT_TYPE,
63+
{
64+
job_id: jobId,
65+
datafeed_id: datafeedId ?? null,
66+
type: jobType,
67+
},
68+
{ id: jobId, overwrite: true }
69+
);
7270
}
7371

7472
async function _bulkCreateJobs(jobs: JobObject[], namespaces?: string[]) {
7573
await isMlReady();
7674
return await savedObjectsClient.bulkCreate<JobObject>(
7775
jobs.map((j) => ({
7876
type: ML_SAVED_OBJECT_TYPE,
77+
id: j.job_id,
7978
attributes: j,
8079
initialNamespaces: namespaces,
8180
}))

0 commit comments

Comments
 (0)