Skip to content

Commit

Permalink
adding ids to saved objects
Browse files Browse the repository at this point in the history
  • Loading branch information
jgowdyelastic committed Nov 10, 2020
1 parent b81496e commit 51bbb2b
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions x-pack/plugins/ml/server/saved_objects/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,24 +58,23 @@ 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<JobObject>(ML_SAVED_OBJECT_TYPE, {
job_id: jobId,
datafeed_id: datafeedId ?? null,
type: jobType,
});
await savedObjectsClient.create<JobObject>(
ML_SAVED_OBJECT_TYPE,
{
job_id: jobId,
datafeed_id: datafeedId ?? null,
type: jobType,
},
{ id: jobId, overwrite: true }
);
}

async function _bulkCreateJobs(jobs: JobObject[], namespaces?: string[]) {
await isMlReady();
return await savedObjectsClient.bulkCreate<JobObject>(
jobs.map((j) => ({
type: ML_SAVED_OBJECT_TYPE,
id: j.job_id,
attributes: j,
initialNamespaces: namespaces,
}))
Expand Down

0 comments on commit 51bbb2b

Please sign in to comment.