Files
jobboard/app/static/jobs.js
T
WolfandClaude Fable 5.1 8532e4e739 Runs is the queue's elements and a Problems log; a Kill lands between boards
Run one stage goes: the cascade is the unit of work and app job keeps the
per-stage entry points. The pull button is disabled while a pull runs and
the lede no longer hardcodes the cadence. Messages folds into Runs as
Problems. pull_batch checks for a cancel before every board, one plugin per
target, and both plugins now close their HTTP client.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-28 16:10:38 +02:00

72 lines
2.7 KiB
JavaScript

/* The Runs section of Sources: "Run the pull now" and the idle line.
*
* 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.
*/
(function () {
"use strict";
const pullButton = document.getElementById("pull-now");
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", 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();
}
});
}
/* `<desk-jobs>` takes up no space while the queue is idle, so the line that
says so is the app's to show and hide. It starts hidden: until the first
snapshot nobody knows whether the queue is idle. */
function update(state) {
const idle = document.getElementById("idle");
if (idle) {
const busy = (state.running || []).length + (state.queued || []).length;
idle.hidden = busy > 0;
}
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);
})();