moved l-a-s in here
This commit is contained in:
parent
1e3e55e362
commit
836ab07776
18 changed files with 3946 additions and 281 deletions
26
lib/admin/server.js
Normal file
26
lib/admin/server.js
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
const moment = require('moment')
|
||||
|
||||
const db = require('../db')
|
||||
|
||||
const CONSIDERED_UP = 30000
|
||||
|
||||
function status () {
|
||||
const sql = `select extract(epoch from (now() - created)) as age
|
||||
from server_events
|
||||
where event_type=$1
|
||||
order by created desc
|
||||
limit 1`
|
||||
|
||||
return db.oneOrNone(sql, ['ping'])
|
||||
.then(row => {
|
||||
if (!row) return {up: false, lastPing: null}
|
||||
|
||||
const age = moment.duration(row.age, 'seconds')
|
||||
const up = age.asMilliseconds() < CONSIDERED_UP
|
||||
const lastPing = age.humanize()
|
||||
|
||||
return {up, lastPing}
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = {status}
|
||||
Loading…
Add table
Add a link
Reference in a new issue