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

First prod push #1

Merged
merged 10 commits into from
Aug 2, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Health check
  • Loading branch information
Vikas Agarwal committed Aug 2, 2021
commit 6c079bb140e0a21640cf756d0adf64356f88d026
33 changes: 33 additions & 0 deletions src/modules/health/controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* Controller for health check endpoint
*/
const models = require('../../models')
const config = require('config')
const logger = require('../../common/logger')

// the topcoder-healthcheck-dropin library returns checksRun count,
// here it follows that to return such count
let checksRun = 0

/**
* Check health of the DB
* @param {Object} req the request
* @param {Object} res the response
*/
async function checkHealth (req, res) {
checksRun += 1
await models
.validate()
.then(() => {
logger.info({ component: 'HealthCheckController', context: 'checkHealth', message: 'Connection has been established successfully.' })
})
.catch(err => {
logger.logFullError(err, { component: 'HealthCheckController', context: 'checkHealth' })
res.status(503)
})
res.send({ checksRun })
}

module.exports = {
checkHealth
}
13 changes: 13 additions & 0 deletions src/modules/health/route.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* the skill routes
*/

const Controller = require('./controller')

module.exports = {
'/health': {
get: {
method: Controller.checkHealth
}
}
}