How do you get the variable from a SIGINT/SIGTERM/uncaughtException? To be passed on a healthCheck endpoint? Here is what I have been coded so far:logger.js const log = require('./log'); let healthy = true; let exception = null; process.on('SIGINT', function () { healthy = false; log.error('SERVER', 'ERROR'); }); process.on('SIGTERM', function () { healthy = false; log.error('SERVER', 'ERROR'); }); process.on('uncaughtException', function (error) { healthy = false; exception = error; log.error('SERVER', 'ERROR: ', error); }); module.exports = { healthy, exception } server.js ... let eventLogger = require('./logger'); eventLogger; ... app.get('/healthCheck', function (req, res, next) { if (eventLogger.healthy) { res.sendStatus(200) logger.info('HEALTHCHECK', 'OK'); } else { res.sendStatus(500) logger.error('HEALTHCHECK', 'FAIL', 'ERROR', eventLogger.exception); } }); I am able to check the healthy variable to be true, and false once it hits any of the process event however when I hit the endpoint healthCheck it always return OK.
Submitted December 05, 2018 at 09:12AM by Kopikoblack
No comments:
Post a Comment