This commit is contained in:
Josh Harvey 2017-03-20 16:43:40 +02:00
parent a35e9d2d44
commit 340ad2b518
8 changed files with 129 additions and 38 deletions

View file

@ -11,10 +11,13 @@ function machinesLastPing () {
const sql = `select name, min(extract(epoch from (now() - machine_events.created))) as age
from machine_events, devices
where machine_events.device_id = devices.device_id
and devices.paired
group by name`
return db.any(sql)
.then(r => {
if (r.length === 0) return 'No paired machines'
const downRows = r.filter(row => row.age > CONSIDERED_UP_SECS)
if (downRows.length === 0) return 'All machines are up'
@ -54,6 +57,7 @@ function status () {
}]
return {up, lastPing, rates, machineStatus}
})
.catch(() => ({up, lastPing, rates: [], machineStatus}))
})
})
}