indicate non-configured server

This commit is contained in:
Josh Harvey 2017-05-31 15:08:33 +01:00
parent e8356c1041
commit acaf343b64
5 changed files with 75 additions and 29 deletions

View file

@ -9,6 +9,12 @@ const machineLoader = require('../machine-loader')
const CONSIDERED_UP_SECS = 30
function checkWasConfigured () {
settingsLoader.loadLatest()
.then(() => true)
.catch(() => false)
}
function machinesLastPing () {
const sql = `select min(extract(epoch from (now() - created))) as age
from machine_events
@ -46,8 +52,8 @@ function status () {
order by created desc
limit 1`
return Promise.all([db.oneOrNone(sql, ['ping']), machinesLastPing()])
.then(([statusRow, machineStatus]) => {
return Promise.all([checkWasConfigured(), db.oneOrNone(sql, ['ping']), machinesLastPing()])
.then(([wasConfigured, statusRow, machineStatus]) => {
const age = statusRow && moment.duration(statusRow.age, 'seconds')
const up = statusRow ? statusRow.age < CONSIDERED_UP_SECS : false
const lastPing = statusRow && age.humanize()
@ -56,7 +62,7 @@ function status () {
.catch(() => null)
.then(settings => {
return getRates(settings)
.then(rates => ({up, lastPing, rates, machineStatus}))
.then(rates => ({wasConfigured, up, lastPing, rates, machineStatus}))
})
})
}