Fix check pings query

This commit is contained in:
Rafael Taranto 2019-05-13 23:41:21 -03:00 committed by Josh Harvey
parent 1a467707e8
commit 15c8e0d862
3 changed files with 15 additions and 2 deletions

View file

@ -128,7 +128,7 @@ function checkStuckScreen (deviceEvents, machineName) {
} }
function checkPing (device) { function checkPing (device) {
const sql = `select (EXTRACT(EPOCH FROM (now() - created))) * 1000 AS age from machine_pings const sql = `select (EXTRACT(EPOCH FROM (now() - updated))) * 1000 AS age from machine_pings
where device_id=$1` where device_id=$1`
const deviceId = device.deviceId const deviceId = device.deviceId
return db.oneOrNone(sql, [deviceId]) return db.oneOrNone(sql, [deviceId])

View file

@ -255,7 +255,7 @@ function plugins (settings, deviceId) {
return Promise.all([ return Promise.all([
db.none(`insert into machine_pings(device_id, device_time) values($1, $2) db.none(`insert into machine_pings(device_id, device_time) values($1, $2)
ON CONFLICT (device_id) DO UPDATE SET device_time = $2`, [deviceId, deviceTime]), ON CONFLICT (device_id) DO UPDATE SET device_time = $2, updated = now()`, [deviceId, deviceTime]),
db.none(pgp.helpers.update(devices, null, 'devices') + 'WHERE device_id = ${deviceId}', { db.none(pgp.helpers.update(devices, null, 'devices') + 'WHERE device_id = ${deviceId}', {
deviceId deviceId
}) })

View file

@ -0,0 +1,13 @@
const db = require('./db')
exports.up = function (next) {
var sql = [
'ALTER TABLE machine_pings RENAME COLUMN created to updated'
]
db.multi(sql, next)
}
exports.down = function (next) {
next()
}