Skip to content

Commit 816c665

Browse files
Merge pull request #95 from Discookie/ericsson/fix-duplicate-tasks
Deduplicate scheduled tasks based on command line
2 parents fc426e2 + ca49767 commit 816c665

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

src/backend/executor/process.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,24 @@ export class ExecutorManager implements Disposable {
282282
const name = process.processParameters.processType!;
283283
let namedQueue = this.queue.get(name) ?? [];
284284

285+
// When adding the same process as the currently running one, assume that its underlying data was changed,
286+
// and kill the currently active process
287+
if (this.activeProcess?.commandLine === process.commandLine) {
288+
this.killProcess();
289+
}
290+
291+
// The exact same task with the exact same commandline won't be added twice
292+
if (namedQueue.some((queueItem) => queueItem.commandLine === process.commandLine)) {
293+
// In Prepend mode, this means removing and re-adding to move the task to the front of the queue
294+
if (method === 'prepend') {
295+
namedQueue = namedQueue.filter((queueItem) => queueItem.commandLine !== process.commandLine);
296+
} else {
297+
// Otherwise, keep the process in the queue as is, to preserve its position
298+
this.startNextProcess();
299+
return;
300+
}
301+
}
302+
285303
switch (method) {
286304
case 'replace':
287305
namedQueue = [process];

0 commit comments

Comments
 (0)