WIPP
This commit is contained in:
parent
a375adb8b9
commit
c3261bc61a
5 changed files with 101 additions and 106 deletions
|
|
@ -7,7 +7,6 @@ const crypto = require('crypto')
|
|||
const dbm = require('./postgresql_interface')
|
||||
const db = require('./db')
|
||||
const logger = require('./logger')
|
||||
const notifier = require('./notifier')
|
||||
const T = require('./time')
|
||||
const configManager = require('./config-manager')
|
||||
const ticker = require('./ticker')
|
||||
|
|
@ -16,8 +15,6 @@ const exchange = require('./exchange')
|
|||
const sms = require('./sms')
|
||||
const email = require('./email')
|
||||
|
||||
const CHECK_NOTIFICATION_INTERVAL = 30 * T.seconds
|
||||
const ALERT_SEND_INTERVAL = T.hour
|
||||
const STALE_INCOMING_TX_AGE = T.week
|
||||
const STALE_LIVE_INCOMING_TX_AGE = 10 * T.minutes
|
||||
const MAX_NOTIFY_AGE = 2 * T.days
|
||||
|
|
@ -34,9 +31,6 @@ const coins = {
|
|||
ETH: {unitScale: 18}
|
||||
}
|
||||
|
||||
let alertFingerprint = null
|
||||
let lastAlertTime = null
|
||||
|
||||
function plugins (settings) {
|
||||
function buildRates (deviceId, tickers) {
|
||||
const config = configManager.machineScoped(deviceId, settings.config)
|
||||
|
|
@ -407,56 +401,6 @@ function plugins (settings) {
|
|||
return Promise.all(promises)
|
||||
}
|
||||
|
||||
function sendNoAlerts () {
|
||||
const subject = '[Lamassu] All clear'
|
||||
const rec = {
|
||||
sms: {
|
||||
body: subject
|
||||
},
|
||||
email: {
|
||||
subject,
|
||||
body: 'No errors are reported for your machines.'
|
||||
}
|
||||
}
|
||||
return sendMessage(rec)
|
||||
}
|
||||
|
||||
function checkNotification () {
|
||||
return notifier.checkStatus()
|
||||
.then(alertRec => {
|
||||
const currentAlertFingerprint = notifier.alertFingerprint(alertRec)
|
||||
if (!currentAlertFingerprint) {
|
||||
const inAlert = !!alertFingerprint
|
||||
alertFingerprint = null
|
||||
lastAlertTime = null
|
||||
if (inAlert) return sendNoAlerts()
|
||||
}
|
||||
|
||||
const alertChanged = currentAlertFingerprint === alertFingerprint &&
|
||||
lastAlertTime - Date.now() < ALERT_SEND_INTERVAL
|
||||
if (alertChanged) return
|
||||
|
||||
const subject = notifier.alertSubject(alertRec)
|
||||
const rec = {
|
||||
sms: {
|
||||
body: subject
|
||||
},
|
||||
email: {
|
||||
subject,
|
||||
body: notifier.printEmailAlerts(alertRec)
|
||||
}
|
||||
}
|
||||
alertFingerprint = currentAlertFingerprint
|
||||
lastAlertTime = Date.now()
|
||||
|
||||
return sendMessage(rec)
|
||||
})
|
||||
.then(results => {
|
||||
if (results && results.length > 0) logger.debug('Successfully sent alerts')
|
||||
})
|
||||
.catch(logger.error)
|
||||
}
|
||||
|
||||
function checkDeviceBalances (deviceId) {
|
||||
const config = configManager.machineScoped(deviceId, settings.config)
|
||||
const cryptoCodes = config.cryptoCurrencies
|
||||
|
|
@ -489,12 +433,6 @@ function plugins (settings) {
|
|||
})
|
||||
}
|
||||
|
||||
function startCheckingNotification (config) {
|
||||
notifier.init(checkBalances)
|
||||
checkNotification()
|
||||
setInterval(checkNotification, CHECK_NOTIFICATION_INTERVAL)
|
||||
}
|
||||
|
||||
function randomCode () {
|
||||
return new BigNumber(crypto.randomBytes(3).toString('hex'), 16).shift(-6).toFixed(6).slice(-6)
|
||||
}
|
||||
|
|
@ -564,7 +502,6 @@ function plugins (settings) {
|
|||
sendCoins,
|
||||
cashOut,
|
||||
dispenseAck,
|
||||
startCheckingNotification,
|
||||
getPhoneCode,
|
||||
fetchPhoneTx,
|
||||
executeTrades,
|
||||
|
|
@ -574,7 +511,9 @@ function plugins (settings) {
|
|||
monitorIncoming,
|
||||
monitorUnnotified,
|
||||
sweepLiveHD,
|
||||
sweepOldHD
|
||||
sweepOldHD,
|
||||
sendMessage,
|
||||
checkBalances
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue