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:
@@ -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();
|
||||
}
|
||||
Reference in New Issue
Block a user