Skip to content

Commit

Permalink
Merge pull request #322 from keyhash/feature/send-email-on-rpc-error
Browse files Browse the repository at this point in the history
Send an email when the worker cannot get the last block header
  • Loading branch information
Snipa22 authored Feb 25, 2018
2 parents 43ed584 + 774a525 commit c8d07c9
Showing 1 changed file with 32 additions and 10 deletions.
42 changes: 32 additions & 10 deletions lib/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.`
);
}
})
});

});
}

Expand Down

0 comments on commit c8d07c9

Please sign in to comment.