Added health check api endpoint
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
import LibraryNodes from '/imports/api/library/LibraryNodes.js';
|
||||
|
||||
LibraryNodes.startCaching();
|
||||
LibraryNodes.startCaching?.();
|
||||
|
||||
37
app/imports/server/rest/apiPublications/healthCheck.js
Normal file
37
app/imports/server/rest/apiPublications/healthCheck.js
Normal file
@@ -0,0 +1,37 @@
|
||||
// A simple endpoint that does a single round trip to the database to check everything is working
|
||||
|
||||
const HealthCheckCollection = new Mongo.Collection('healthCheck');
|
||||
|
||||
// Don't use redis oplog optimization on this collection, we want to hit the database every time
|
||||
HealthCheckCollection.disableRedis?.();
|
||||
|
||||
const healthCheckDoc = {
|
||||
status: 'ok',
|
||||
};
|
||||
|
||||
// Add the health check doc on startup if it's missing
|
||||
// There should only be this single doc in the collection
|
||||
// A capped collection would be marginally faster, but it's a pain to make one in Meteor
|
||||
Meteor.startup(function () {
|
||||
if (!HealthCheckCollection.findOne()) {
|
||||
HealthCheckCollection.insert(healthCheckDoc);
|
||||
}
|
||||
});
|
||||
|
||||
Meteor.method('api-status', function () {
|
||||
let dbHealthDoc;
|
||||
try {
|
||||
dbHealthDoc = HealthCheckCollection.findOne();
|
||||
} catch (e) {
|
||||
this.setHttpStatusCode(503);
|
||||
}
|
||||
if (dbHealthDoc?.status === 'ok') {
|
||||
this.setHttpStatusCode(200);
|
||||
} else {
|
||||
this.setHttpStatusCode(500);
|
||||
}
|
||||
return dbHealthDoc || {};
|
||||
}, {
|
||||
httpMethod: 'GET',
|
||||
url: 'api/status'
|
||||
});
|
||||
@@ -1 +1,2 @@
|
||||
import './creature.js';
|
||||
import './healthCheck.js';
|
||||
|
||||
2
app/package-lock.json
generated
2
app/package-lock.json
generated
@@ -1917,7 +1917,7 @@
|
||||
"lodash.omit": {
|
||||
"version": "4.5.0",
|
||||
"resolved": "https://registry.npmjs.org/lodash.omit/-/lodash.omit-4.5.0.tgz",
|
||||
"integrity": "sha1-brGa5aHuHdnfC5aeZs4Lf6MLXmA="
|
||||
"integrity": "sha512-XeqSp49hNGmlkj2EJlfrQFIzQ6lXdNro9sddtQzcJY8QaoC2GO0DT7xaIokHeyM+mIT0mPMlPvkYzg2xCuHdZg=="
|
||||
},
|
||||
"lodash.template": {
|
||||
"version": "4.5.0",
|
||||
|
||||
Reference in New Issue
Block a user