diff --git a/lib/worker.js b/lib/worker.js index cb0b499..1a0e545 100644 --- a/lib/worker.js +++ b/lib/worker.js @@ -504,20 +504,42 @@ function updateWalletStats() { } +let lastBlockCheckIsOk = true; function monitorNodes() { - global.mysql.query("SELECT blockID, hostname, ip FROM pools WHERE last_checkin > date_sub(now(), interval 30 minute)").then(function (rows) { - global.coinFuncs.getLastBlockHeader(function (err, block) { - if (err !== null){ - console.error("Issue in getting block header. Skipping node monitor"); - return; + global.coinFuncs.getLastBlockHeader((err, block) => { + if (err !== null) { + if (lastBlockCheckIsOk) { + lastBlockCheckIsOk = false; + global.support.sendEmail( + global.config.general.adminEmail, + 'Failed to query daemon for last block header', + `The worker failed to return last block header. Please verify if the daemon is running properly.` + ); } - rows.forEach(function (row) { - if (row.blockID < block.height - 3) { - global.support.sendEmail(global.config.general.adminEmail, "Pool server behind in blocks", "The pool server: "+row.hostname+" with IP: "+row.ip+" is "+(block.height - row.blockID)+ " blocks behind"); - } - } + return + } + if (!lastBlockCheckIsOk) { + lastBlockCheckIsOk = true; + global.support.sendEmail( + global.config.general.adminEmail, + 'Quering daemon for last block header is back to normal', + `An warning was sent to you indicating that the the worker failed to return the last block header. + The issue seems to be solved now.` ); + } + const sql = 'SELECT blockID, hostname, ip FROM pools WHERE last_checkin > DATE_SUB(NOW(), INTERVAL 30 MINUTE)'; + global.mysql.query(sql).then(pools => { + pools.forEach(({ blockID, hostname, ip }) => { + if (blockID < block.height - 3) { + global.support.sendEmail( + global.config.general.adminEmail, + 'Pool server is behind in blocks', + `The pool server: ${hostname} with IP: ${ip} is ${(block.height - blockID)} blocks behind.` + ); + } + }) }); + }); }