aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-05-18 15:11:00 +0200
committermetamuffin <metamuffin@disroot.org>2025-05-18 15:11:00 +0200
commit441142f26921510a049d6a8458026c7c6d962ca1 (patch)
tree39d19bbb3b4801ba3b47bcde0d0572007faedcd7
parentf59dcc4a77412750f8dde72ed335a8262206ef5d (diff)
downloadisda-441142f26921510a049d6a8458026c7c6d962ca1.tar
isda-441142f26921510a049d6a8458026c7c6d962ca1.tar.bz2
isda-441142f26921510a049d6a8458026c7c6d962ca1.tar.zst
fix a few live updating bugs
-rw-r--r--scripts/dummy_worker.ts3
-rw-r--r--src/webui.rs2
-rw-r--r--src/worker_ws.rs6
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<Arc<RwLock<State>>>) -> Html<String> {
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<RwLock<State>>) {
// 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 {