From 441142f26921510a049d6a8458026c7c6d962ca1 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Sun, 18 May 2025 15:11:00 +0200 Subject: fix a few live updating bugs --- scripts/dummy_worker.ts | 3 ++- src/webui.rs | 2 +- src/worker_ws.rs | 6 +++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/scripts/dummy_worker.ts b/scripts/dummy_worker.ts index 00e6ad2..1bbe0c7 100644 --- a/scripts/dummy_worker.ts +++ b/scripts/dummy_worker.ts @@ -4,7 +4,7 @@ const ws = new WebSocket(Deno.args[0]) async function do_work(key: string) { let progress = 0 while (progress < 1) { - await new Promise(r => setTimeout(r, 200)) + await new Promise(r => setTimeout(r, Math.random() * 400)) progress += 0.1 ws.send(JSON.stringify({ t: "metadata", key, data: { progress } })) } @@ -17,6 +17,7 @@ ws.onopen = () => { console.log("ws open"); ws.send(JSON.stringify({ t: "register", name: "dummy worker", task_kinds: ["youtube"] })) ws.send(JSON.stringify({ t: "accept" })) + ws.send(JSON.stringify({ t: "accept" })) } ws.onmessage = async ev => { if (typeof ev.data != "string") return diff --git a/src/webui.rs b/src/webui.rs index 61ea324..17eb5e0 100644 --- a/src/webui.rs +++ b/src/webui.rs @@ -39,7 +39,7 @@ pub(crate) async fn webui(S(state): S>>) -> Html { title { "Queue-Server" } } body { - section.workers { + section[id="workers"] { h2 { "Workers"} ul { @for (id, w) in &g.workers { li { @Worker { id: *id, w } } diff --git a/src/worker_ws.rs b/src/worker_ws.rs index c98e08d..25ec7b0 100644 --- a/src/worker_ws.rs +++ b/src/worker_ws.rs @@ -143,7 +143,8 @@ async fn worker_websocket_inner(ws: WebSocket, state: Arc>) { // recycle incomplete tasks for key in w.assigned_tasks { g.loading.remove(&key); - g.queue.insert(key); + g.queue.insert(key.clone()); + g.send_webui_task_update(&key); } g.send_webui_worker_removal(worker); } @@ -163,6 +164,7 @@ impl State { WorkerRequest::Register { name, task_kinds } => { worker.name = name; worker.task_kinds = task_kinds; + self.send_webui_worker_update(w); } WorkerRequest::Metadata { key, data } => { let m = self.metadata.entry(key.clone()).or_default(); @@ -199,6 +201,7 @@ impl State { self.loading.remove(&key); self.complete.insert(key.clone()); self.send_webui_task_update(&key); + self.send_webui_worker_update(w); } else { bail!("task was not assigned") } @@ -239,6 +242,7 @@ impl State { self.queue.remove(&key); self.loading.insert(key.clone()); self.send_webui_task_update(&key); + self.send_webui_worker_update(w); self.send_to_worker( w, WorkerResponse::Work { -- cgit v1.2.3-70-g09d2