Feat: warn admin before restarting services
This commit is contained in:
parent
a432d913be
commit
6994303069
6 changed files with 126 additions and 8 deletions
|
|
@ -1,4 +1,6 @@
|
|||
const _ = require('lodash/fp')
|
||||
const db = require('./db')
|
||||
const pgp = require('pg-promise')()
|
||||
|
||||
function getInsertQuery (tableName, fields) {
|
||||
// outputs string like: '$1, $2, $3...' with proper No of items
|
||||
|
|
@ -48,6 +50,16 @@ exports.machineEvent = function machineEvent (rec) {
|
|||
.then(() => db.none(deleteSql))
|
||||
}
|
||||
|
||||
exports.machineEventsByIdBatch = function machineEventsByIdBatch (machineIds) {
|
||||
const formattedIds = _.map(pgp.as.text, machineIds).join(',')
|
||||
const sql = `SELECT *, (EXTRACT(EPOCH FROM (now() - created))) * 1000 AS age FROM machine_events WHERE device_id IN ($1^) ORDER BY age ASC LIMIT 1`
|
||||
return db.any(sql, [formattedIds]).then(res => {
|
||||
const events = _.map(_.mapKeys(_.camelCase))(res)
|
||||
const eventMap = _.groupBy('deviceId', events)
|
||||
return machineIds.map(id => _.prop([0], eventMap[id]))
|
||||
})
|
||||
}
|
||||
|
||||
exports.machineEvents = function machineEvents () {
|
||||
const sql = 'SELECT *, (EXTRACT(EPOCH FROM (now() - created))) * 1000 AS age FROM machine_events'
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue