Increase time to consider machine stuck (#211)

* Increase time to consider machine stuck

* Fix standard styling issues
This commit is contained in:
Rafael Taranto 2018-11-15 11:20:26 -02:00 committed by Josh Harvey
parent 599c865f37
commit eb033a4174
2 changed files with 12 additions and 12 deletions

View file

@ -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 }

View file

@ -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 }