Skip to content

Instantly share code, notes, and snippets.

@srevenant
Last active September 6, 2018 18:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save srevenant/f51703e213c49bf34c7cec27443aa854 to your computer and use it in GitHub Desktop.
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
/* 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