From 59b76ebeb2acbd01a01fe34b4e74700e1d716ad4 Mon Sep 17 00:00:00 2001 From: John Newby Date: Fri, 21 Oct 2022 14:17:49 +0000 Subject: [PATCH] Added tez balance monitoring for health check --- app.mjs | 12 +++++++++++- config.example.json | 11 ++++++----- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/app.mjs b/app.mjs index 6723097..0883894 100644 --- a/app.mjs +++ b/app.mjs @@ -69,8 +69,18 @@ const main = async function() { queue.save_state(ids, state).catch((err) => { console.error("Database error when setting", state, "on operation with ids:", JSON.stringify(ids)); });; } + const health_check = async function() { + let tez_supply = await tezos.tz.getBalance(address); + tez_supply = tez_supply.shiftedBy(-6).toNumber(); + if (tez_supply > config.warnBelowTez) { + await queue.kill_canaries(address); + } else { + console.warn(`Tez balance on account ${address} below warning threshold`); + } + }; + const heartbeat = async function() { - await queue.kill_canaries(address); + await health_check(); let ops = await queue.checkout(address, ~~(config.batchSize/batch_divider) + 1); if (ops.length == 0) { diff --git a/config.example.json b/config.example.json index d3e416d..e6a5925 100644 --- a/config.example.json +++ b/config.example.json @@ -5,12 +5,13 @@ "rpcUrl": "http://immensely.newby.org:8734/", "pollingDelay": 10000, "timeout": 300, + "warnBelowTez": 10.0, "dbConnection": { "user": "tezos", - "password": "tezos", - "host": "localhost", - "port": 5432, - "database": "tezos" + "password": "tezos", + "host": "localhost", + "port": 5432, + "database": "tezos" }, "handlers": { "nft": { @@ -24,4 +25,4 @@ "args": {} } } -} \ No newline at end of file +}