Implement Node Monitor Service

- Check in with online nodes every n ms
- Update nodes that do not reply
- Added node object record helper
- Updated mysql wrapper for updating node info to accept bool or number
This commit is contained in:
Logan Cusano
2023-05-07 02:41:58 -04:00
parent 7b2215e9da
commit 9b2d0c4bbb
5 changed files with 141 additions and 51 deletions

View File

@@ -39,30 +39,22 @@ exports.sendHttpRequest = function sendHttpRequest(requestOptions, data, callbac
res.on('data', (data) => {
const responseObject = {
"statusCode": res.statusCode,
"body": data
"body": (requestOptions.method === "POST") ? JSON.parse(data) : data.toString()
};
try {
responseObject.body = JSON.parse(responseObject.body)
}
catch (err) {
}
log.DEBUG("Response Object: ", responseObject);
return callback(responseObject);
callback(responseObject);
})
}).on('error', err => {
log.ERROR('Error: ', err.message)
if (err.code === "ECONNREFUSED"){
// Bot refused connection, assumed offline
log.WARN("Connection Refused");
}
else log.ERROR('Error: ', err.message, err);
callback(undefined);
// TODO need to handle if the server is down
})
if (requestOptions.timeout) {
req.setTimeout(requestOptions.timeout, () => {
return callback(false);
});
}
// Write the data to the request and send it
req.write(data)
req.end()
req.write(data);
req.end();
}