mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-10 06:34:05 -08:00
🚀 Include DB check in health-check
This commit is contained in:
parent
52808ea460
commit
e19bdbf6d7
|
@ -3,6 +3,9 @@ import {
|
||||||
dirname as pathDirname,
|
dirname as pathDirname,
|
||||||
join as pathJoin,
|
join as pathJoin,
|
||||||
} from 'path';
|
} from 'path';
|
||||||
|
import {
|
||||||
|
getConnectionManager,
|
||||||
|
} from "typeorm";
|
||||||
import * as bodyParser from 'body-parser';
|
import * as bodyParser from 'body-parser';
|
||||||
import * as history from 'connect-history-api-fallback';
|
import * as history from 'connect-history-api-fallback';
|
||||||
import * as requestPromise from 'request-promise-native';
|
import * as requestPromise from 'request-promise-native';
|
||||||
|
@ -226,12 +229,29 @@ class App {
|
||||||
// ----------------------------------------
|
// ----------------------------------------
|
||||||
|
|
||||||
|
|
||||||
// Creates a new workflow
|
// Does very basic health check
|
||||||
this.app.get('/healthz', ResponseHelper.send(async (req: express.Request, res: express.Response): Promise<IDataObject> => {
|
this.app.get('/healthz', async (req: express.Request, res: express.Response) => {
|
||||||
return {
|
|
||||||
|
const connectionManager = getConnectionManager();
|
||||||
|
|
||||||
|
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);
|
||||||
|
return ResponseHelper.sendErrorResponse(res, error);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Everything fine
|
||||||
|
const responseData = {
|
||||||
status: 'ok',
|
status: 'ok',
|
||||||
};
|
};
|
||||||
}));
|
|
||||||
|
ResponseHelper.sendSuccessResponse(res, responseData, true, 200);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue