Skip to content

Commit

Permalink
Handle multiple jobs with the same name (#4825)
Browse files Browse the repository at this point in the history
  • Loading branch information
garrettjstevens authored Feb 9, 2025
1 parent 1746d7e commit 36fb12a
Showing 1 changed file with 39 additions and 13 deletions.
52 changes: 39 additions & 13 deletions plugins/jobs-management/src/JobsListWidget/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ export function stateModelFactory(_pluginManager: PluginManager) {
* #action
*/
addJob(job: NewJob) {
const { cancelCallback } = job
const { cancelCallback, name } = job
const existing = self.jobs.find(job => job.name === name)
if (existing) {
return existing
}
const length = self.jobs.push(job)
const addedJob = self.jobs[length - 1]!
addedJob.setCancelCallback(cancelCallback)
Expand All @@ -58,39 +62,61 @@ export function stateModelFactory(_pluginManager: PluginManager) {
*/
removeJob(jobName: string) {
const indx = self.jobs.findIndex(job => job.name === jobName)
const removed = self.jobs[indx]
self.jobs.splice(indx, 1)
return removed
if (indx === -1) {
return undefined
}
const removed = self.jobs.splice(indx, 1)
return removed[0]
},
/**
* #action
*/
addFinishedJob(job: NewJob) {
self.finished.push(job)
return self.finished
const existing = self.finished.find(
finishedJob => finishedJob.name === job.name,
)
if (existing) {
return existing
}
const length = self.finished.push(job)
return self.finished[length - 1]
},
/**
* #action
*/
addQueuedJob(job: NewJob) {
self.queued.push(job)
return self.finished
const existing = self.queued.find(
queuedJob => queuedJob.name === job.name,
)
if (existing) {
return existing
}
const length = self.queued.push(job)
return self.queued[length - 1]
},
/**
* #action
*/
addAbortedJob(job: NewJob) {
self.aborted.push(job)
return self.aborted
const existing = self.aborted.find(
abortedJob => abortedJob.name === job.name,
)
if (existing) {
return existing
}
const length = self.aborted.push(job)
return self.aborted[length - 1]
},
/**
* #action
*/
removeQueuedJob(jobName: string) {
const indx = self.queued.findIndex(job => job.name === jobName)
const removed = self.queued[indx]
self.queued.splice(indx, 1)
return removed
if (indx === -1) {
return undefined
}
const removed = self.queued.splice(indx, 1)
return removed[0]
},
/**
* #action
Expand Down

0 comments on commit 36fb12a

Please sign in to comment.