aboutsummaryrefslogtreecommitdiffstats
path: root/static/modules/sbbuilder.js
blob: 357133fd65031f826205df3dcaef59fb48b204a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// 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
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

// The build VM has no tab: on the Dashboard it is a running slot while a job
// is active, and nothing otherwise.

export const interval = 10;   // each poll is an ssh round trip

const ACTIVE = ["running", "busy", "starting"];
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(" · ");
}