generated from hmcts/expressjs-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathhealth.ts
More file actions
39 lines (33 loc) · 1.03 KB
/
health.ts
File metadata and controls
39 lines (33 loc) · 1.03 KB
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
import healthcheck from '@hmcts/nodejs-healthcheck';
import { Application } from 'express';
import { app as myApp } from '../app';
import { Logger } from '@modules/logger';
function shutdownCheck(): boolean {
return myApp.locals.shutdown;
}
export default function (app: Application): void {
const logger = Logger.getLogger('health');
const healthCheckConfig = {
checks: {},
readinessChecks: {
redis: healthcheck.raw(() => {
if (!app.locals.redisClient) {
return Promise.resolve(false);
}
return app.locals.redisClient
.ping()
.then((_: string) => {
return healthcheck.status(_ === 'PONG');
})
.catch((error: Error) => {
logger.error('Health check failed on redis', error);
return healthcheck.status(false);
});
}),
shutdownCheck: healthcheck.raw(() => {
return shutdownCheck() ? healthcheck.down() : healthcheck.up();
}),
},
};
healthcheck.addTo(app, healthCheckConfig);
}