🐛 Fix db connection check /healthz (#2041)

* 🐛 fix db connection check

* 👕 fix missing semi

*  Revert "🐛 Hardcode typeorm@0.2.34 as new version makes health-check fail"

This reverts commit ddee2ec47c.

* 🐛 fix health-check in WebhookServer
This commit is contained in:
Ben Hesseldieck 2021-08-08 12:04:04 +02:00 committed by GitHub
parent 72d57537de
commit ffecbc7004
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 64 additions and 61 deletions

View file

@ -120,7 +120,7 @@
"sqlite3": "^5.0.1", "sqlite3": "^5.0.1",
"sse-channel": "^3.1.1", "sse-channel": "^3.1.1",
"tslib": "1.14.1", "tslib": "1.14.1",
"typeorm": "0.2.34", "typeorm": "^0.2.30",
"winston": "^3.3.3" "winston": "^3.3.3"
}, },
"jest": { "jest": {

View file

@ -466,16 +466,18 @@ class App {
// Does very basic health check // Does very basic health check
this.app.get('/healthz', async (req: express.Request, res: express.Response) => { this.app.get('/healthz', async (req: express.Request, res: express.Response) => {
const connectionManager = getConnectionManager(); const connection = getConnectionManager().get();
if (connectionManager.connections.length === 0) { try {
const error = new ResponseHelper.ResponseError('No Database connection found!', undefined, 503); if (connection.isConnected === false) {
return ResponseHelper.sendErrorResponse(res, error); // Connection is not active
} throw new Error('No active database connection!');
}
if (connectionManager.connections[0].isConnected === false) { // DB ping
// Connection is not active await connection.query('SELECT 1');
const error = new ResponseHelper.ResponseError('Database connection not active!', undefined, 503); } catch (err) {
LoggerProxy.error('No Database connection!', err);
const error = new ResponseHelper.ResponseError('No Database connection!', undefined, 503);
return ResponseHelper.sendErrorResponse(res, error); return ResponseHelper.sendErrorResponse(res, error);
} }

View file

@ -248,16 +248,17 @@ class App {
// Does very basic health check // Does very basic health check
this.app.get('/healthz', async (req: express.Request, res: express.Response) => { this.app.get('/healthz', async (req: express.Request, res: express.Response) => {
const connectionManager = getConnectionManager(); const connection = getConnectionManager().get();
if (connectionManager.connections.length === 0) { try {
const error = new ResponseHelper.ResponseError('No Database connection found!', undefined, 503); if (connection.isConnected === false) {
return ResponseHelper.sendErrorResponse(res, error); // Connection is not active
} throw new Error('No active database connection!');
}
if (connectionManager.connections[0].isConnected === false) { // DB ping
// Connection is not active await connection.query('SELECT 1');
const error = new ResponseHelper.ResponseError('Database connection not active!', undefined, 503); } catch (err) {
const error = new ResponseHelper.ResponseError('No Database connection!', undefined, 503);
return ResponseHelper.sendErrorResponse(res, error); return ResponseHelper.sendErrorResponse(res, error);
} }