format for latest standard
This commit is contained in:
parent
4108efd9c7
commit
c2af183911
77 changed files with 1697 additions and 1693 deletions
|
|
@ -11,8 +11,8 @@ const CONSIDERED_UP_SECS = 30
|
|||
|
||||
function checkWasConfigured () {
|
||||
return settingsLoader.loadLatest()
|
||||
.then(() => true)
|
||||
.catch(() => false)
|
||||
.then(() => true)
|
||||
.catch(() => false)
|
||||
}
|
||||
|
||||
function machinesLastPing () {
|
||||
|
|
@ -21,28 +21,28 @@ function machinesLastPing () {
|
|||
group by device_id`
|
||||
|
||||
return Promise.all([machineLoader.getMachineNames(), db.any(sql)])
|
||||
.then(([machines, events]) => {
|
||||
if (machines.length === 0) return 'No paired machines'
|
||||
.then(([machines, events]) => {
|
||||
if (machines.length === 0) return 'No paired machines'
|
||||
|
||||
const addName = event => {
|
||||
const machine = _.find(['deviceId', event.deviceId], machines)
|
||||
if (!machine) return null
|
||||
return _.set('name', machine.name, event)
|
||||
}
|
||||
const addName = event => {
|
||||
const machine = _.find(['deviceId', event.deviceId], machines)
|
||||
if (!machine) return null
|
||||
return _.set('name', machine.name, event)
|
||||
}
|
||||
|
||||
const mapper = _.flow(_.filter(row => row.age > CONSIDERED_UP_SECS), _.map(addName), _.compact)
|
||||
const downRows = mapper(events)
|
||||
const mapper = _.flow(_.filter(row => row.age > CONSIDERED_UP_SECS), _.map(addName), _.compact)
|
||||
const downRows = mapper(events)
|
||||
|
||||
if (downRows.length === 0) return 'All machines are up'
|
||||
if (downRows.length === 0) return 'All machines are up'
|
||||
|
||||
if (downRows.length === 1) {
|
||||
const row = downRows[0]
|
||||
const age = moment.duration(row.age, 'seconds')
|
||||
return `${row.name} down for ${age.humanize()}`
|
||||
}
|
||||
if (downRows.length === 1) {
|
||||
const row = downRows[0]
|
||||
const age = moment.duration(row.age, 'seconds')
|
||||
return `${row.name} down for ${age.humanize()}`
|
||||
}
|
||||
|
||||
return 'Multiple machines down'
|
||||
})
|
||||
return 'Multiple machines down'
|
||||
})
|
||||
}
|
||||
|
||||
function status () {
|
||||
|
|
@ -53,32 +53,32 @@ function status () {
|
|||
limit 1`
|
||||
|
||||
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()
|
||||
.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()
|
||||
|
||||
return settingsLoader.loadLatest()
|
||||
.catch(() => null)
|
||||
.then(settings => {
|
||||
return getRates(settings)
|
||||
.then(rates => ({wasConfigured, up, lastPing, rates, machineStatus}))
|
||||
return settingsLoader.loadLatest()
|
||||
.catch(() => null)
|
||||
.then(settings => {
|
||||
return getRates(settings)
|
||||
.then(rates => ({wasConfigured, up, lastPing, rates, machineStatus}))
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function getRates (settings) {
|
||||
if (!settings) return Promise.resolve([])
|
||||
|
||||
return ticker.getRates(settings, 'USD', 'BTC')
|
||||
.then(ratesRec => {
|
||||
return [{
|
||||
crypto: 'BTC',
|
||||
bid: parseFloat(ratesRec.rates.bid),
|
||||
ask: parseFloat(ratesRec.rates.ask)
|
||||
}]
|
||||
})
|
||||
.catch(() => [])
|
||||
.then(ratesRec => {
|
||||
return [{
|
||||
crypto: 'BTC',
|
||||
bid: parseFloat(ratesRec.rates.bid),
|
||||
ask: parseFloat(ratesRec.rates.ask)
|
||||
}]
|
||||
})
|
||||
.catch(() => [])
|
||||
}
|
||||
|
||||
module.exports = {status}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue