mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[ML] Fixing job id reuse when previous job was in diffrent space (#86270)
This commit is contained in:
parent
011849faea
commit
b1d18e5d9e
1 changed files with 16 additions and 2 deletions
|
@ -77,7 +77,17 @@ export function jobSavedObjectServiceFactory(
|
|||
const id = savedObjectId(job);
|
||||
|
||||
try {
|
||||
await savedObjectsClient.delete(ML_SAVED_OBJECT_TYPE, id, { force: true });
|
||||
const [existingJobObject] = await getAllJobObjectsForAllSpaces(jobType, jobId);
|
||||
if (existingJobObject !== undefined) {
|
||||
// a saved object for this job already exists, this may be left over from a previously deleted job
|
||||
if (existingJobObject.namespaces?.length) {
|
||||
// use a force delete just in case the saved object exists only in another space.
|
||||
await _forceDeleteJob(jobType, jobId, existingJobObject.namespaces[0]);
|
||||
} else {
|
||||
// the saved object has no spaces, this is unexpected, attempt a normal delete
|
||||
await savedObjectsClient.delete(ML_SAVED_OBJECT_TYPE, id, { force: true });
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
// the saved object may exist if a previous job with the same ID has been deleted.
|
||||
// if not, this error will be throw which we ignore.
|
||||
|
@ -168,7 +178,7 @@ export function jobSavedObjectServiceFactory(
|
|||
return jobObject;
|
||||
}
|
||||
|
||||
async function getAllJobObjectsForAllSpaces(jobType?: JobType) {
|
||||
async function getAllJobObjectsForAllSpaces(jobType?: JobType, jobId?: string) {
|
||||
await isMlReady();
|
||||
const filterObject: JobObjectFilter = {};
|
||||
|
||||
|
@ -176,6 +186,10 @@ export function jobSavedObjectServiceFactory(
|
|||
filterObject.type = jobType;
|
||||
}
|
||||
|
||||
if (jobId !== undefined) {
|
||||
filterObject.job_id = jobId;
|
||||
}
|
||||
|
||||
const { filter, searchFields } = createSavedObjectFilter(filterObject);
|
||||
const options: SavedObjectsFindOptions = {
|
||||
type: ML_SAVED_OBJECT_TYPE,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue