mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-24 04:04:06 -08:00
🐛 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:
parent
72d57537de
commit
ffecbc7004
|
@ -120,7 +120,7 @@
|
|||
"sqlite3": "^5.0.1",
|
||||
"sse-channel": "^3.1.1",
|
||||
"tslib": "1.14.1",
|
||||
"typeorm": "0.2.34",
|
||||
"typeorm": "^0.2.30",
|
||||
"winston": "^3.3.3"
|
||||
},
|
||||
"jest": {
|
||||
|
|
|
@ -466,16 +466,18 @@ class App {
|
|||
// Does very basic health check
|
||||
this.app.get('/healthz', async (req: express.Request, res: express.Response) => {
|
||||
|
||||
const connectionManager = getConnectionManager();
|
||||
const connection = getConnectionManager().get();
|
||||
|
||||
if (connectionManager.connections.length === 0) {
|
||||
const error = new ResponseHelper.ResponseError('No Database connection found!', undefined, 503);
|
||||
return ResponseHelper.sendErrorResponse(res, error);
|
||||
}
|
||||
|
||||
if (connectionManager.connections[0].isConnected === false) {
|
||||
// Connection is not active
|
||||
const error = new ResponseHelper.ResponseError('Database connection not active!', undefined, 503);
|
||||
try {
|
||||
if (connection.isConnected === false) {
|
||||
// Connection is not active
|
||||
throw new Error('No active database connection!');
|
||||
}
|
||||
// DB ping
|
||||
await connection.query('SELECT 1');
|
||||
} catch (err) {
|
||||
LoggerProxy.error('No Database connection!', err);
|
||||
const error = new ResponseHelper.ResponseError('No Database connection!', undefined, 503);
|
||||
return ResponseHelper.sendErrorResponse(res, error);
|
||||
}
|
||||
|
||||
|
|
|
@ -248,16 +248,17 @@ class App {
|
|||
// Does very basic health check
|
||||
this.app.get('/healthz', async (req: express.Request, res: express.Response) => {
|
||||
|
||||
const connectionManager = getConnectionManager();
|
||||
const connection = getConnectionManager().get();
|
||||
|
||||
if (connectionManager.connections.length === 0) {
|
||||
const error = new ResponseHelper.ResponseError('No Database connection found!', undefined, 503);
|
||||
return ResponseHelper.sendErrorResponse(res, error);
|
||||
}
|
||||
|
||||
if (connectionManager.connections[0].isConnected === false) {
|
||||
// Connection is not active
|
||||
const error = new ResponseHelper.ResponseError('Database connection not active!', undefined, 503);
|
||||
try {
|
||||
if (connection.isConnected === false) {
|
||||
// Connection is not active
|
||||
throw new Error('No active database connection!');
|
||||
}
|
||||
// DB ping
|
||||
await connection.query('SELECT 1');
|
||||
} catch (err) {
|
||||
const error = new ResponseHelper.ResponseError('No Database connection!', undefined, 503);
|
||||
return ResponseHelper.sendErrorResponse(res, error);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue