From eb033a4174bc7684e14db4f154b8c6c8404a85fe Mon Sep 17 00:00:00 2001 From: Rafael Taranto Date: Thu, 15 Nov 2018 11:20:26 -0200 Subject: [PATCH] Increase time to consider machine stuck (#211) * Increase time to consider machine stuck * Fix standard styling issues --- lib/notifier.js | 20 ++++++++++---------- lib/poller.js | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/notifier.js b/lib/notifier.js index e6ddbf04..20b5e00a 100644 --- a/lib/notifier.js +++ b/lib/notifier.js @@ -8,7 +8,7 @@ const db = require('./db') const T = require('./time') const logger = require('./logger') -const STALE_STATE = 2 * T.minute +const STALE_STATE = 7 * T.minute const NETWORK_DOWN_TIME = 1 * T.minute const ALERT_SEND_INTERVAL = T.hour @@ -99,9 +99,9 @@ const getDeviceTime = _.flow(_.get('device_time'), Date.parse) function dropRepeatsWith (comparator, arr) { const iteratee = (acc, val) => val === acc.last ? acc - : {arr: _.concat(acc.arr, val), last: val} + : { arr: _.concat(acc.arr, val), last: val } - return _.reduce(iteratee, {arr: []}, arr).arr + return _.reduce(iteratee, { arr: [] }, arr).arr } function checkStuckScreen (deviceEvents) { @@ -122,7 +122,7 @@ function checkStuckScreen (deviceEvents) { const age = Math.floor(lastEvent.age) if (age > STALE_STATE) { - return [{code: STALE, state: state, age: age}] + return [{ code: STALE, state, age }] } return [] @@ -136,8 +136,8 @@ function checkPing (deviceId) { return db.oneOrNone(sql, [deviceId]) .then(row => { - if (!row) return [{code: PING}] - if (row.age > NETWORK_DOWN_TIME) return [{code: PING, age: row.age}] + if (!row) return [{ code: PING }] + if (row.age > NETWORK_DOWN_TIME) return [{ code: PING, age: row.age }] return [] }) } @@ -151,7 +151,7 @@ function checkPings (devices) { } function checkStatus (plugins) { - const alerts = {devices: {}, deviceNames: {}} + const alerts = { devices: {}, deviceNames: {} } return Promise.all([plugins.checkBalances(), dbm.machineEvents(), plugins.getMachineNames()]) .then(([balances, events, devices]) => { @@ -188,12 +188,12 @@ function emailAlert (alert) { switch (alert.code) { case PING: if (alert.age) { - const pingAge = prettyMs(alert.age, {compact: true, verbose: true}) + const pingAge = prettyMs(alert.age, { compact: true, verbose: true }) return `Machine down for ${pingAge}` } return 'Machine down for a while.' case STALE: - const stuckAge = prettyMs(alert.age, {compact: true, verbose: true}) + const stuckAge = prettyMs(alert.age, { compact: true, verbose: true }) return `Machine is stuck on ${alert.state} screen for ${stuckAge}` case LOW_CRYPTO_BALANCE: const balance = formatCurrency(alert.fiatBalance.balance, alert.fiatCode) @@ -245,4 +245,4 @@ function buildAlertFingerprint (alertRec) { return crypto.createHash('sha256').update(subject).digest('hex') } -module.exports = {checkNotification} +module.exports = { checkNotification } diff --git a/lib/poller.js b/lib/poller.js index 64681bdb..aa8d44a7 100644 --- a/lib/poller.js +++ b/lib/poller.js @@ -50,7 +50,7 @@ function updateCoinAtmRadar () { const config = settings().config return pi().getRates() - .then(rates => coinAtmRadar.update({rates, config})) + .then(rates => coinAtmRadar.update({ rates, config })) } function start (__settings) { @@ -79,4 +79,4 @@ function start (__settings) { setInterval(updateCoinAtmRadar, RADAR_UPDATE_INTERVAL) } -module.exports = {start, reload} +module.exports = { start, reload }