new admin structure
This commit is contained in:
parent
7d82874916
commit
c2282e61b4
17 changed files with 5768 additions and 1204 deletions
|
|
@ -1,24 +1,32 @@
|
|||
const _ = require('lodash/fp')
|
||||
const moment = require('moment')
|
||||
|
||||
const ticker = require('../ticker')
|
||||
const settingsLoader = require('../settings-loader')
|
||||
|
||||
const db = require('../db')
|
||||
const machineLoader = require('../machine-loader')
|
||||
|
||||
const CONSIDERED_UP_SECS = 30
|
||||
|
||||
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`
|
||||
const sql = `select min(extract(epoch from (now() - created))) as age
|
||||
from machine_events
|
||||
group by device_id`
|
||||
|
||||
return db.any(sql)
|
||||
.then(r => {
|
||||
if (r.length === 0) return 'No paired machines'
|
||||
return Promise.all([machineLoader.getMachineNames(), db.any(sql)])
|
||||
.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 mapper = _.flow(_.filter(row => row.age > CONSIDERED_UP_SECS), _.map(addName), _.compact)
|
||||
const downRows = mapper(events)
|
||||
|
||||
const downRows = r.filter(row => row.age > CONSIDERED_UP_SECS)
|
||||
if (downRows.length === 0) return 'All machines are up'
|
||||
|
||||
if (downRows.length === 1) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue