Increase time to consider machine stuck (#211)
* Increase time to consider machine stuck * Fix standard styling issues
This commit is contained in:
parent
599c865f37
commit
eb033a4174
2 changed files with 12 additions and 12 deletions
|
|
@ -8,7 +8,7 @@ const db = require('./db')
|
||||||
const T = require('./time')
|
const T = require('./time')
|
||||||
const logger = require('./logger')
|
const logger = require('./logger')
|
||||||
|
|
||||||
const STALE_STATE = 2 * T.minute
|
const STALE_STATE = 7 * T.minute
|
||||||
const NETWORK_DOWN_TIME = 1 * T.minute
|
const NETWORK_DOWN_TIME = 1 * T.minute
|
||||||
const ALERT_SEND_INTERVAL = T.hour
|
const ALERT_SEND_INTERVAL = T.hour
|
||||||
|
|
||||||
|
|
@ -99,9 +99,9 @@ const getDeviceTime = _.flow(_.get('device_time'), Date.parse)
|
||||||
function dropRepeatsWith (comparator, arr) {
|
function dropRepeatsWith (comparator, arr) {
|
||||||
const iteratee = (acc, val) => val === acc.last
|
const iteratee = (acc, val) => val === acc.last
|
||||||
? acc
|
? 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) {
|
function checkStuckScreen (deviceEvents) {
|
||||||
|
|
@ -122,7 +122,7 @@ function checkStuckScreen (deviceEvents) {
|
||||||
|
|
||||||
const age = Math.floor(lastEvent.age)
|
const age = Math.floor(lastEvent.age)
|
||||||
if (age > STALE_STATE) {
|
if (age > STALE_STATE) {
|
||||||
return [{code: STALE, state: state, age: age}]
|
return [{ code: STALE, state, age }]
|
||||||
}
|
}
|
||||||
|
|
||||||
return []
|
return []
|
||||||
|
|
@ -136,8 +136,8 @@ function checkPing (deviceId) {
|
||||||
|
|
||||||
return db.oneOrNone(sql, [deviceId])
|
return db.oneOrNone(sql, [deviceId])
|
||||||
.then(row => {
|
.then(row => {
|
||||||
if (!row) return [{code: PING}]
|
if (!row) return [{ code: PING }]
|
||||||
if (row.age > NETWORK_DOWN_TIME) return [{code: PING, age: row.age}]
|
if (row.age > NETWORK_DOWN_TIME) return [{ code: PING, age: row.age }]
|
||||||
return []
|
return []
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -151,7 +151,7 @@ function checkPings (devices) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkStatus (plugins) {
|
function checkStatus (plugins) {
|
||||||
const alerts = {devices: {}, deviceNames: {}}
|
const alerts = { devices: {}, deviceNames: {} }
|
||||||
|
|
||||||
return Promise.all([plugins.checkBalances(), dbm.machineEvents(), plugins.getMachineNames()])
|
return Promise.all([plugins.checkBalances(), dbm.machineEvents(), plugins.getMachineNames()])
|
||||||
.then(([balances, events, devices]) => {
|
.then(([balances, events, devices]) => {
|
||||||
|
|
@ -188,12 +188,12 @@ function emailAlert (alert) {
|
||||||
switch (alert.code) {
|
switch (alert.code) {
|
||||||
case PING:
|
case PING:
|
||||||
if (alert.age) {
|
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 ${pingAge}`
|
||||||
}
|
}
|
||||||
return 'Machine down for a while.'
|
return 'Machine down for a while.'
|
||||||
case STALE:
|
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}`
|
return `Machine is stuck on ${alert.state} screen for ${stuckAge}`
|
||||||
case LOW_CRYPTO_BALANCE:
|
case LOW_CRYPTO_BALANCE:
|
||||||
const balance = formatCurrency(alert.fiatBalance.balance, alert.fiatCode)
|
const balance = formatCurrency(alert.fiatBalance.balance, alert.fiatCode)
|
||||||
|
|
@ -245,4 +245,4 @@ function buildAlertFingerprint (alertRec) {
|
||||||
return crypto.createHash('sha256').update(subject).digest('hex')
|
return crypto.createHash('sha256').update(subject).digest('hex')
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {checkNotification}
|
module.exports = { checkNotification }
|
||||||
|
|
|
||||||
|
|
@ -50,7 +50,7 @@ function updateCoinAtmRadar () {
|
||||||
const config = settings().config
|
const config = settings().config
|
||||||
|
|
||||||
return pi().getRates()
|
return pi().getRates()
|
||||||
.then(rates => coinAtmRadar.update({rates, config}))
|
.then(rates => coinAtmRadar.update({ rates, config }))
|
||||||
}
|
}
|
||||||
|
|
||||||
function start (__settings) {
|
function start (__settings) {
|
||||||
|
|
@ -79,4 +79,4 @@ function start (__settings) {
|
||||||
setInterval(updateCoinAtmRadar, RADAR_UPDATE_INTERVAL)
|
setInterval(updateCoinAtmRadar, RADAR_UPDATE_INTERVAL)
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {start, reload}
|
module.exports = { start, reload }
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue