-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathhealthcheck.js
40 lines (35 loc) · 1.06 KB
/
healthcheck.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
'use strict';
const healthcheck = require('@hmcts/nodejs-healthcheck');
const logger = require('app/components/logger')('Init');
const os = require('os');
const config = require('config');
const checks = {};
const readinessChecks = {};
if (config.services.pcqBackend.enabled === 'true') {
checks['pcq-backend'] = healthcheck.web(`${config.services.pcqBackend.url}/health/readiness`, {
callback: (err, res) => {
const status = err ? 'DOWN' : res.body.status || 'DOWN';
if (status === 'DOWN') {
logger.warn('pcq-backend is DOWN');
logger.warn(err);
}
return status === 'UP' ? healthcheck.up() : healthcheck.down();
},
timeout: 10000,
deadline: 20000
});
}
const setup = app => {
healthcheck.addTo(app, {
checks: checks,
readinessChecks: readinessChecks,
buildInfo: {
name: config.service.name,
host: os.hostname(),
uptime: process.uptime(),
}
});
};
module.exports = {
setup: setup
};