web/queue: add remuxing progress & general improvements

and a bunch of other stuff:
- size and percentage in queue
- indeterminate progress bar
- if libav wasm freezes, the worker kill itself
- cleaner states
- cleaner props
This commit is contained in:
wukko
2025-01-25 01:25:53 +06:00
parent c4c47bdc27
commit 44a99bdb3a
12 changed files with 117 additions and 53 deletions

View File

@@ -1,8 +1,8 @@
import RemuxWorker from "$lib/workers/remux?worker";
//import RemoveBgWorker from "$lib/workers/removebg?worker";
import type { CobaltPipelineItem } from "$lib/types/workers";
import { itemDone, itemError } from "$lib/state/queen-bee/queue";
import { updateWorkerProgress } from "$lib/state/queen-bee/current-tasks";
const workerError = (parentId: string, workerId: string, worker: Worker, error: string) => {
itemError(parentId, workerId, error);
@@ -26,13 +26,43 @@ export const runRemuxWorker = async (workerId: string, parentId: string, file: F
workerError(parentId, workerId, worker, "internal error");
};
// sometimes chrome refuses to start libav wasm,
// so we check the health and kill self if it doesn't spawn
let bumpAttempts = 0;
const startCheck = setInterval(() => {
bumpAttempts++;
if (bumpAttempts === 8) {
worker.terminate();
console.error("worker didn't start after 4 seconds, so it was killed");
// TODO: proper error code
return workerError(parentId, workerId, worker, "worker didn't start");
}
}, 500);
let totalDuration: number | null = null;
worker.onmessage = (event) => {
const eventData = event.data.cobaltRemuxWorker;
if (!eventData) return;
console.log(eventData);
// temporary debug logging
console.log(JSON.stringify(eventData, null, 2));
// TODO: calculate & use progress again
clearInterval(startCheck);
if (eventData.progress) {
if (eventData.progress.duration) {
totalDuration = eventData.progress.duration;
}
updateWorkerProgress(workerId, {
percentage: totalDuration ? (eventData.progress.durationProcessed / totalDuration) * 100 : 0,
size: eventData.progress.size,
})
}
if (eventData.render) {
return workerSuccess(

View File

@@ -23,16 +23,16 @@ export const checkTasks = () => {
// one parent & pipeline
const pipelineItem = task.pipeline[i];
startWorker(pipelineItem);
addWorkerToQueue({
id: pipelineItem.workerId,
addWorkerToQueue(pipelineItem.workerId, {
parentId: task.id,
step: i + 1,
totalSteps: task.pipeline.length,
});
itemRunning(task.id, i);
itemRunning(
task.id,
pipelineItem.workerId
);
startWorker(pipelineItem);
break;
}
break;