web/queue: in-place queue task retrying
Some checks failed
Run tests / check lockfile correctness (push) Has been cancelled
Run tests / web sanity check (push) Has been cancelled
Run tests / api sanity check (push) Has been cancelled
CodeQL / Analyze (${{ matrix.language }}) (none, javascript-typescript) (push) Has been cancelled

no more duplicate tasks
This commit is contained in:
wukko
2025-05-19 22:49:54 +06:00
parent 479a64890e
commit 98cd4dfc0d
4 changed files with 24 additions and 5 deletions

View File

@@ -15,6 +15,8 @@ const startPipeline = (pipelineItem: CobaltPipelineItem) => {
startWorker(pipelineItem);
}
// this is really messy, sorry to whoever
// reads this in the future (probably myself)
export const schedule = () => {
const queueItems = get(queue);
const ongoingTasks = get(currentTasks);
@@ -58,7 +60,13 @@ export const schedule = () => {
}
// start the nearest waiting task and wait to be called again
else if (task.state === "waiting" && task.pipeline.length > 0) {
else if (task.state === "waiting" && task.pipeline.length > 0 && Object.keys(ongoingTasks).length === 0) {
// this is really bad but idk how to prevent tasks from running simultaneously
// on retry if a later task is running & user restarts an old task
for (const task of Object.values(queueItems)) {
if (task.state === "running") return;
}
startPipeline(task.pipeline[0]);
// break because we don't want to start next tasks before this one is done