diff --git a/lib/notifier.js b/lib/notifier.js index c1522e75..afad9582 100644 --- a/lib/notifier.js +++ b/lib/notifier.js @@ -128,7 +128,7 @@ function checkStuckScreen (deviceEvents, machineName) { } 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` const deviceId = device.deviceId return db.oneOrNone(sql, [deviceId]) diff --git a/lib/plugins.js b/lib/plugins.js index 1e2b274c..30458979 100644 --- a/lib/plugins.js +++ b/lib/plugins.js @@ -255,7 +255,7 @@ function plugins (settings, deviceId) { return Promise.all([ 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}', { deviceId }) diff --git a/migrations/1557800959028-machine-pings-rename.js b/migrations/1557800959028-machine-pings-rename.js new file mode 100644 index 00000000..9475b96f --- /dev/null +++ b/migrations/1557800959028-machine-pings-rename.js @@ -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() +}