Last active
September 6, 2018 18:12
-
-
Save srevenant/f51703e213c49bf34c7cec27443aa854 to your computer and use it in GitHub Desktop.
Designed for use with reflex's version-check https://github.com/reflexsc/reflex/blob/master/dev/version-check
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* bring in configs, and backends, like db */ | |
/* const config = require('config') */ | |
let healthy = true | |
setInterval(() => { | |
// check db pools, maybe run a query, etc. | |
try { | |
if (db.check_health()) { // but do this with a timelimit that is less than check interval seconds | |
healthy = true | |
return | |
} | |
} catch (err) { | |
console.log("DB Health check failure! " + err) | |
} | |
healthy = false | |
}, config.healthcheck_interval_seconds * 1000) | |
// assume node express | |
router.get('/health', (req, res, next) => { | |
if (healthy) { | |
if (req.query.detail === 'true') { | |
res.status(200).send({'version': config.build.version, status: 'OK'}) | |
} else { | |
res.status(204).send() | |
} | |
} else { | |
res.status(503).send({'version': config.build.version, status: 'UNHEALTHY'} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment