aboutsummaryrefslogtreecommitdiffstats
path: root/static/modules/sbbuilder.js
diff options
context:
space:
mode:
Diffstat (limited to 'static/modules/sbbuilder.js')
-rw-r--r--static/modules/sbbuilder.js95
1 files changed, 21 insertions, 74 deletions
diff --git a/static/modules/sbbuilder.js b/static/modules/sbbuilder.js
index 6285dd5..357133f 100644
--- a/static/modules/sbbuilder.js
+++ b/static/modules/sbbuilder.js
@@ -1,4 +1,4 @@
-// deck-it - sbbuilder panel
+// deck-it - the build VM's running slot
// Copyright (C) 2026 Danilo M. <danix@danix.xyz>
//
// This program is free software; you can redistribute it and/or modify
@@ -14,80 +14,27 @@
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-import { offline } from "../offline.js";
+// The build VM has no tab: on the Dashboard it is a running slot while a job
+// is active, and nothing otherwise.
-const gib = (b) => (b == null ? "?" : (b / 1073741824).toFixed(1));
-const pct = (n) => (n == null ? "?" : `${Math.round(n)}%`);
-const ago = (ts) => {
- if (!ts) return "—";
- const d = Math.max(0, Math.floor(Date.now() / 1000 - ts));
- if (d < 3600) return `${Math.floor(d / 60)}m`;
- if (d < 86400) return `${Math.floor(d / 3600)}h`;
- return `${Math.floor(d / 86400)}d`;
-};
+export const interval = 10; // each poll is an ssh round trip
const ACTIVE = ["running", "busy", "starting"];
-
-function tile(label, value, sub) {
- const d = document.createElement("div");
- d.className = "mtile";
- const l = document.createElement("span");
- l.className = "mlabel";
- l.textContent = label;
- const v = document.createElement("span");
- v.className = "mvalue num";
- v.textContent = value;
- const s = document.createElement("span");
- s.className = "msub";
- s.textContent = sub || "";
- d.append(l, v, s);
- return d;
+const active = (st) => (st.jobs ?? []).filter((j) => ACTIVE.includes(j.status));
+
+export const busy = (st) => !st.offline && active(st).length > 0;
+
+export function slot(st, el) {
+ if (!el.firstChild) {
+ el.innerHTML = `<i class="nf sic"></i>
+ <span class="what"><span></span></span><span class="pct num"></span>
+ <span class="meta"><span></span></span>
+ <div class="bar busy"><i></i></div>`;
+ }
+ const jobs = active(st);
+ const load = st.stats?.load;
+ el.querySelector(".what > span").textContent = `Build VM · ${jobs[0]?.kind || "job"}`;
+ el.querySelector(".pct").textContent = jobs.length > 1 ? `${jobs.length} jobs` : "";
+ el.querySelector(".meta > span").textContent =
+ [jobs[0]?.status, load ? `load ${load[0].toFixed(2)}` : null].filter(Boolean).join(" · ");
}
-
-export default {
- title: "Build VM",
- interval: 10,
-
- mount(el) {
- el.innerHTML = `<div class="sbb"></div>`;
- },
-
- update(state, el) {
- const box = el.querySelector(".sbb");
- if (state.offline) {
- offline(box, {
- icon: "/icons/virt-manager.svg",
- title: "Build VM is off",
- detail: "Start the VM and its jobs and package counts appear here.",
- });
- return;
- }
- box.textContent = "";
- const s = state.stats ?? {};
- const p = s.packages ?? {};
- const sr = s.slackrepo ?? {};
- const results = sr.results ?? {};
- const jobs = state.jobs ?? [];
- const running = jobs.find((j) => ACTIVE.includes(j.status));
-
- const now = document.createElement("div");
- now.className = "sbb-now";
- now.textContent = running ? `● ${running.kind || "job"}` : "idle";
- now.classList.toggle("warn", Boolean(running));
- box.append(now);
-
- const overlays = Object.entries(p).filter(([k]) => k !== "total" && k !== "shadowed");
- box.append(
- tile("Packages", String(p.total ?? "?"), overlays.map(([k, v]) => `${k} ${v}`).join(" · ")),
- tile("Failed", String(results.failed ?? 0), `${sr.built ?? "?"} built`),
- tile("Disk free", `${gib(s.disk?.free)}`, `of ${gib(s.disk?.total)} GiB`),
- tile("CPU", pct(s.cpu), `load ${s.load ? s.load[0].toFixed(2) : "?"}`),
- );
-
- const foot = document.createElement("div");
- foot.className = "mfoot";
- foot.textContent = `orphans ${s.orphans ?? "?"} · ${
- Object.entries(s.sync ?? {}).map(([k, v]) => `${k} ${ago(v)}`).join(" · ") || "no pulls"}`;
- box.append(foot);
- },
-};