web/ProcessingQueue: include worker progress in global progress

This commit is contained in:
jj 2025-01-25 19:46:04 +00:00
parent 7c3e1e6779
commit af18bcd43f
No known key found for this signature in database

View File

@ -3,7 +3,7 @@
import { onNavigate } from "$app/navigation"; import { onNavigate } from "$app/navigation";
import type { SvelteComponent } from "svelte"; import type { SvelteComponent } from "svelte";
import { clearQueue, queue } from "$lib/state/queen-bee/queue"; import { clearQueue, queue as readableQueue } from "$lib/state/queen-bee/queue";
import SectionHeading from "$components/misc/SectionHeading.svelte"; import SectionHeading from "$components/misc/SectionHeading.svelte";
import PopoverContainer from "$components/misc/PopoverContainer.svelte"; import PopoverContainer from "$components/misc/PopoverContainer.svelte";
@ -17,11 +17,15 @@
let popover: SvelteComponent; let popover: SvelteComponent;
$: expanded = false; $: expanded = false;
$: queueItems = Object.entries($queue); $: queue = Object.entries($readableQueue);
$: queueLength = Object.keys($queue).length;
$: cleanQueueLength = queueItems.filter(([id, item]) => item.state !== "error").length; $: totalProgress = queue.length ? queue.map(([, item]) => {
$: completedQueueItems = queueItems.filter(([id, item]) => item.state === "done").length; if (item.state === "done" || item.state === "error")
return 100;
else if (item.state === "running")
return $currentTasks[item.runningWorker]?.progress?.percentage || 0;
return 0;
}).reduce((a, b) => a + b) / (100 * queue.length) : 0;
// TODO: toggle this only when progress is unknown // TODO: toggle this only when progress is unknown
$: indeterminate = false; $: indeterminate = false;
@ -37,7 +41,7 @@
<div id="processing-queue" class:expanded> <div id="processing-queue" class:expanded>
<ProcessingStatus <ProcessingStatus
progress={(completedQueueItems / cleanQueueLength) * 100} progress={totalProgress * 100}
{indeterminate} {indeterminate}
expandAction={popover?.showPopover} expandAction={popover?.showPopover}
/> />
@ -57,7 +61,7 @@
nolink nolink
/> />
<div class="header-buttons"> <div class="header-buttons">
{#if queueLength > 0} {#if queue.length}
<button class="clear-button" on:click={clearQueue}> <button class="clear-button" on:click={clearQueue}>
<IconX /> <IconX />
{$t("button.clear")} {$t("button.clear")}
@ -66,7 +70,7 @@
</div> </div>
</div> </div>
<div id="processing-list"> <div id="processing-list">
{#each queueItems as [id, item]} {#each queue as [id, item]}
<ProcessingQueueItem <ProcessingQueueItem
{id} {id}
info={item} info={item}
@ -75,7 +79,7 @@
} }
/> />
{/each} {/each}
{#if queueLength === 0} {#if queue.length === 0}
<ProcessingQueueStub /> <ProcessingQueueStub />
{/if} {/if}
</div> </div>