add bitcoin balance check
This commit is contained in:
parent
12a1dcbf9a
commit
f48ce99744
1 changed files with 23 additions and 5 deletions
|
|
@ -3,9 +3,11 @@
|
|||
var R = require('ramda')
|
||||
|
||||
var db = null
|
||||
var getBalance = null
|
||||
|
||||
function init (_db) {
|
||||
function init (_db, _getBalance) {
|
||||
db = _db
|
||||
getBalance = _getBalance
|
||||
}
|
||||
|
||||
function toInt10 (str) { return parseInt(str, 10) }
|
||||
|
|
@ -18,6 +20,15 @@ function sameState (a, b) {
|
|||
return a.note.sessionId === b.note.sessionId && a.note.state === b.note.state
|
||||
}
|
||||
|
||||
function checkBalance () {
|
||||
var LOW_BALANCE_THRESHOLD = 10
|
||||
if (getBalance() < LOW_BALANCE_THRESHOLD) {
|
||||
return console.log('Bitcoin balance is low [ALERT]')
|
||||
}
|
||||
|
||||
console.log('Bitcoin balance ok [OK]')
|
||||
}
|
||||
|
||||
function checkPing (deviceEvents) {
|
||||
var sortedEvents = R.sortBy(R.compose(toInt10, R.prop('device_time')), R.map(jsonParse, deviceEvents))
|
||||
var lastEvent = R.last(sortedEvents)
|
||||
|
|
@ -67,14 +78,17 @@ function checkStatus () {
|
|||
- Fetch devices from devices table
|
||||
- Fetch all machine_events into memory
|
||||
- For each device, verify the following:
|
||||
- stuck on screen
|
||||
v stuck on screen
|
||||
- last screen is >5m stale and is not idle screen
|
||||
- report stuck on screen and name of screen
|
||||
- not scanning qr codes?
|
||||
- low bitcoins -- need a separate strategy, but server has this info
|
||||
- var fiatBalance = plugins.fiatBalance();
|
||||
- machine isn't pinging server
|
||||
v machine isn't pinging server
|
||||
- jam checking, need report from l-m
|
||||
*/
|
||||
checkBalance()
|
||||
|
||||
db.devices(function (err, devices) {
|
||||
if (err) return console.error(err)
|
||||
|
||||
|
|
@ -97,9 +111,13 @@ function checkStatus () {
|
|||
|
||||
var _db = require('./postgresql_interface')
|
||||
var connectionString = 'postgres://lamassu:lamassu@localhost/lamassu'
|
||||
_db.init(connectionString)
|
||||
|
||||
init(_db)
|
||||
var _getBalance = function () {
|
||||
return 12
|
||||
}
|
||||
|
||||
_db.init(connectionString)
|
||||
init(_db, _getBalance)
|
||||
|
||||
checkStatus()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue