Merge main: the Runs cleanup meets the queue's own idle text

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Fable 5.1 committed 2026-09-28 16:24:24 +02:00
commit c63f348dc9
15 files changed
+275 -229

No files matched your search

+45 -46
View File
@@ -1,11 +1,12 @@
/* The Runs section of Sources: Pull now on top, one button per remaining
* kind under "Run one stage".
/* The Runs section of Sources: the "Run the pull now" button.
*
* The list comes from `/api/jobs/kinds`, which is the registry, so a new
* `@job` in `app/jobs.py` is a new button and this file is not edited --
* except that `pull` itself is pulled out of the list and wired to the
* dedicated button instead of appearing twice. What the queue is doing is
* `<desk-jobs>`'s business, and it draws itself, idle line included.
* What the queue is doing and when it runs next are `<desk-jobs>`' and
* `<desk-schedules>`' business, and they draw themselves. The single stages
* have no buttons: the cascade is the unit of work, and `app job <stage>`
* keeps the per-stage entry points.
*
* Both read the `app:jobs` snapshot from live.js rather than asking the
* elements, which keep to a shadow root and owe nobody an answer.
*
* Failures are the server's sentence through `api()`, which toasts it -- so
* there is no error handling here beyond keeping the button usable.
@@ -14,51 +15,49 @@
(function () {
"use strict";
const host = document.getElementById("kinds");
const pullButton = document.getElementById("pull-now");
async function start(kind, button) {
button.disabled = true;
try {
const job = await window.api("/api/jobs", { method: "POST", body: { kind } });
window.toast.good(`${job.label || kind}: queued.`);
} catch (e) {
/* already toasted */
} finally {
button.disabled = false;
}
let pending = false; // the POST is in the air
let pulling = false; // the latest snapshot has a live pull cascade
/* A pull queued by the button or a schedule is the `pull` job, which
begins a cascade of its own named `pull on its own`, and the chain's
tasks join it; `pull` is the name a cascade started as one would have.
Live while any task has a job queued or running: the pipeline keeps a
finished cascade in the snapshot for a few seconds, and that is not a
pull still going. As newsdesk's Fetch: the whole cascade, not the `pull`
task, which is over seconds in with five tasks to go. */
const isPull = (c) => c.name === "pull" || c.name === "pull on its own";
const live = (c) => (c.tasks || []).some((t) => t.running || t.queued);
function paint() {
if (!pullButton) return;
pullButton.disabled = pending || pulling;
pullButton.title = pulling ? "A pull is running." : "";
}
if (pullButton) {
pullButton.addEventListener("click", () => start("pull", pullButton));
}
async function draw() {
if (!host) return;
let kinds;
try {
kinds = await window.api("/api/jobs/kinds");
} catch (e) {
host.innerHTML = '<span class="muted">could not read the job kinds</span>';
return;
}
kinds = kinds.filter((k) => k.kind !== "pull");
if (!kinds.length) {
host.innerHTML = '<span class="muted">nothing is registered</span>';
return;
}
host.innerHTML = "";
kinds.forEach((k) => {
const button = document.createElement("button");
button.type = "button";
button.className = "secondary";
button.textContent = k.label || k.kind;
button.title = k.solo ? `${k.kind} -- one at a time` : k.kind;
button.dataset.kind = k.kind;
button.addEventListener("click", () => start(k.kind, button));
host.appendChild(button);
pullButton.addEventListener("click", async () => {
pending = true;
paint();
try {
const job = await window.api("/api/jobs", { method: "POST", body: { kind: "pull" } });
window.toast.good(`${job.label || "pull"}: queued.`);
} catch (e) {
/* already toasted */
} finally {
pending = false;
paint();
}
});
}
document.addEventListener("DOMContentLoaded", draw);
function update(state) {
pulling = (state.cascades || []).some((c) => isPull(c) && live(c));
paint();
}
document.addEventListener("app:jobs", (e) => update(e.detail || {}));
// A snapshot that arrived before this script loaded.
if (window.live && window.live.jobs) update(window.live.jobs);
})();