feat(core): Introduce DB health check (#10661)

This commit is contained in:
Iván Ovejero
2024-09-05 11:04:48 +02:00
committed by GitHub
parent 3a8078068e
commit a8e80d0c4b
6 changed files with 59 additions and 3 deletions

View File

@@ -119,11 +119,17 @@ export abstract class AbstractServer {
protected setupPushServer() {}
private async setupHealthCheck() {
// health check should not care about DB connections
// main health check should not care about DB connections
this.app.get('/healthz', async (_req, res) => {
res.send({ status: 'ok' });
});
this.app.get('/healthz/readiness', async (_req, res) => {
return Db.connectionState.connected && Db.connectionState.migrated
? res.status(200).send({ status: 'ok' })
: res.status(503).send({ status: 'error' });
});
const { connectionState } = Db;
this.app.use((_req, res, next) => {
if (connectionState.connected) {