Skip to content
This repository was archived by the owner on Mar 12, 2025. It is now read-only.

Commit 6c079bb

Browse files
author
Vikas Agarwal
committed
Health check
1 parent 5a6b7f5 commit 6c079bb

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

src/modules/health/controller.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/**
2+
* Controller for health check endpoint
3+
*/
4+
const models = require('../../models')
5+
const config = require('config')
6+
const logger = require('../../common/logger')
7+
8+
// the topcoder-healthcheck-dropin library returns checksRun count,
9+
// here it follows that to return such count
10+
let checksRun = 0
11+
12+
/**
13+
* Check health of the DB
14+
* @param {Object} req the request
15+
* @param {Object} res the response
16+
*/
17+
async function checkHealth (req, res) {
18+
checksRun += 1
19+
await models
20+
.validate()
21+
.then(() => {
22+
logger.info({ component: 'HealthCheckController', context: 'checkHealth', message: 'Connection has been established successfully.' })
23+
})
24+
.catch(err => {
25+
logger.logFullError(err, { component: 'HealthCheckController', context: 'checkHealth' })
26+
res.status(503)
27+
})
28+
res.send({ checksRun })
29+
}
30+
31+
module.exports = {
32+
checkHealth
33+
}

src/modules/health/route.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* the skill routes
3+
*/
4+
5+
const Controller = require('./controller')
6+
7+
module.exports = {
8+
'/health': {
9+
get: {
10+
method: Controller.checkHealth
11+
}
12+
}
13+
}

0 commit comments

Comments
 (0)