Published
Edited
Sep 27, 2021
Insert cell
Insert cell
baseurl = "http://localhost:7954/"
Insert cell
async function fetch_endpoint(path) {
let endpoint = baseurl + path
let res = await fetch(endpoint)
let resdata = await res.json()
return resdata
}
Insert cell
async function fetch_sacct() {
return await fetch_endpoint("slurm/sacct")
}
Insert cell
async function fetch_sinfo() {
return await fetch_endpoint("slurm/sinfo")
}
Insert cell
async function fetch_squeue() {
return await fetch_endpoint("slurm/squeue")
}
Insert cell
async function format_output_liter(res) {
let error = res.exit_code != 0
if (error) {
return html`<pre style="color:#ff9966"> ${res.stdout} ${res.stderr} </pre>`
}
return html`<pre> ${res.stdout} ${res.stderr} </pre>`
}
Insert cell
function format_sacct(res) {
if (res.exit_code != 0) {
return html`<pre style="color:#ff9966"> ${res.stdout} ${res.stderr} </pre>`
}
let sacct_output = res.stdout
let lines = sacct_output.trim().split("\n")
lines = lines.map((el, idx) => {
return el.split("|")
})
let fields = lines[0]
let data = lines.slice(1)
let ans = []
for (let arr of data) {
let obj = {}
for (let i = 0; i < fields.length; i++) {
obj[fields[i]] = arr[i]
}
ans.push(obj)
}
return Inputs.table(ans)
}
Insert cell
timer_interval = 30 * 1000 // 30 seconds
Insert cell
timer = {
while (true) {
yield 42;
await Promises.tick(timer_interval);
}
}
Insert cell
viewof update_button = Inputs.button("Update Slurm Status", {})
Insert cell
sinfo_output = {
timer
update_button
return format_output_liter(await fetch_sinfo())
}
Insert cell
sacct_output = {
timer
update_button
return format_sacct(await fetch_sacct())
}
Insert cell
squeue_output = {
timer
update_button
return format_output_liter(await fetch_squeue())
}
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more