web/queue: remove final file from results without swapping for a dummy

This commit is contained in:
wukko 2025-05-24 14:27:30 +06:00
parent 9c16efd3b1
commit 2f6196f6e3
No known key found for this signature in database
GPG Key ID: 3E30B3F26C7B4AA2
3 changed files with 9 additions and 11 deletions

View File

@ -6,15 +6,11 @@ import { clearCurrentTasks, removeWorkerFromQueue } from "$lib/state/task-manage
import type { CobaltQueue, CobaltQueueItem, CobaltQueueItemRunning, UUID } from "$lib/types/queue";
export const DUMMY_FILE = new File([], 'pipeline_result_deleted.bin');
const clearPipelineCache = (queueItem: CobaltQueueItem) => {
if (queueItem.state === "running") {
for (const [ workerId, item ] of Object.entries(queueItem.pipelineResults)) {
if (item.name !== DUMMY_FILE.name) {
removeFromFileStorage(item.name);
queueItem.pipelineResults[workerId] = DUMMY_FILE;
}
removeFromFileStorage(item.name);
delete queueItem.pipelineResults[workerId];
}
} else if (queueItem.state === "done") {
removeFromFileStorage(queueItem.resultFile.name);

View File

@ -53,7 +53,9 @@ export const removeFromFileStorage = async (filename: string) => {
try {
const cobaltDir = await root.getDirectoryHandle(COBALT_PROCESSING_DIR);
await cobaltDir.removeEntry(filename);
} catch {}
} catch {
// catch and ignore
}
}
}

View File

@ -1,7 +1,7 @@
import { get } from "svelte/store";
import { startWorker } from "$lib/task-manager/run-worker";
import { addWorkerToQueue, currentTasks } from "$lib/state/task-manager/current-tasks";
import { DUMMY_FILE, itemDone, itemError, itemRunning, queue } from "$lib/state/task-manager/queue";
import { itemDone, itemError, itemRunning, queue } from "$lib/state/task-manager/queue";
import type { CobaltPipelineItem } from "$lib/types/workers";
@ -28,10 +28,10 @@ export const schedule = () => {
// if all workers are completed, then return the
// the final file and go to the next task
if (Object.keys(task.pipelineResults).length === task.pipeline.length) {
// swap final file for a dummy, so that it doesn't get
// deleted when we clean up the intermediate files
// remove the final file from pipeline results, so that it doesn't
// get deleted when we clean up the intermediate files
const finalFile = task.pipelineResults[finalWorker.workerId];
task.pipelineResults[finalWorker.workerId] = DUMMY_FILE;
delete task.pipelineResults[finalWorker.workerId];
if (finalFile) {
itemDone(task.id, finalFile);