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

Commit c4819e7

Browse files
Merge pull request #14 from topcoder-platform/health-check
Health check
2 parents 3b9e573 + 60d368d commit c4819e7

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

src/common/errors.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,6 @@ module.exports = {
2222
newAuthError: msg => new AppError(401, msg || 'Auth failed.'),
2323
newPermissionError: msg => new AppError(403, msg || 'The entity does not exist.'),
2424
newConflictError: msg => new AppError(409, msg || 'The entity does not exist.'),
25+
serviceUnavailableError: msg => new AppError(503, msg || 'One or more services are not available'),
2526
elasticSearchEnrichError: msg => new AppError(500, msg || 'Elasticsearch enrich failed')
2627
}

src/modules/health/controller.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* the role controller
3+
*/
4+
5+
const service = require('./service')
6+
const helper = require('../../common/helper')
7+
const methods = helper.getControllerMethods(service)
8+
9+
module.exports = {
10+
...methods
11+
}

src/modules/health/route.js

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

src/modules/health/service.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const errors = require('../../common/errors')
2+
const models = require('../../models')
3+
4+
async function get () {
5+
// Check QLDB Connection by retrieving a session
6+
try {
7+
const session = await models.DBHelper.getSession()
8+
9+
session.close()
10+
} catch (e) {
11+
throw errors.serviceUnavailableError(`QLDB is unavailable, ${e.message}`)
12+
}
13+
14+
return { checksRun: 1 }
15+
}
16+
17+
module.exports = { get }

0 commit comments

Comments
 (0)