Comments (6)
Hi @jahluwalia,
excuse me long waiting for an answer.
As far as I've understood your use case is to wait with further server initializations until all dependencies are healthy, right?
The await healthCheck(app);
statement is supposed to wait until the health checks API endpoints are up and listening ( https://hootsuite.github.io/health-checks-api/ ).
Your use case (again if I understood it right) is specific, as it assumes that the server should be considered up & running only when all dependencies are healthy, which not always can be a desired behavior (consider WARN
states of dependencies or the critical/non-critical
semantic described in the README.md
).
If you want to realize your case with the current functionality you could try following:
const healthCheck = require('healthchecks-api');
// a helper method which will wait until all dependencies have desired states
// one can improve it with some timeout-wise approach (calling `reject`in case of a timeout).
const waitForHealth = (service, states = [ 'OK', 'WARN' ]) => new Promise((resolve, reject) => {
const checkHealth = () => {
for (let i=0; i < service.checks.length; i++) {
let check = service.checks[i];
if (!states.includes(check.status.status[0])) {
setTimeout(checkHealth, 1000);
return;
}
}
// all dependencies healthy
resolve();
};
checkHealth();
});
const startServer = async () => {
const app = express();
// the service object will be passed to health check init method where it gets decorated with initialized health checks and then used in further processing
const service = {};
// pass the `service` object in initialization options
await healthCheck(app, { service });
// wait until all endpoints are healthy
await waitForHealth(service, ['OK']);
// rest of initialization steps
}
startServer();
I'll possibly incorporate this helper function in one of next releases.
from node-healthchecks-api.
One small note. As it is totally possible to not start the server until the dependencies are healthy, it isn't very helpful for the server. Once the status endpoints are registered, you can query the server to see if it is healthy. We moved away from this pattern as it doesn't always work. Sometimes a service can partially work (in a degraded state) when certain dependencies are down and not starting it can cause more harm than good.
from node-healthchecks-api.
Sorry, pressed wrong button. Did not mean to close :(
from node-healthchecks-api.
Must agree with @HootAdam that blocking a server start until dependencies are healthy is far away from a common pattern (I've mentioned this already in the previous comment), especially that the server lifecycle is much longer than its start & initialization time and dependencies outages are something acceptable (don't mistake with desired ;) ).
They are subjects to deal with - according to https://www.reactivemanifesto.org/ and in particular health checks are provided to support such outage management (likely in some automated way).
Dependencies outages at the server start & initialization don't differ in this context with any other outages during the server life cycle.
If we would for example think of a use case like some server initialization related sub-process, that would be supposed to wait until eg. a database is up & running because it reads/writes something from/into it - I think that such a process cannot rely on our health checks as the information what they give is a function of time. It means that even when you request for the particular dependency health and the response is OK this can be false even some milliseconds after.
I'd rather design such a process with some retrial strategy for database read/write.
@jahluwalia maybe you could put some more light on the matter by describing your real use case here? Maybe we're missing something?
from node-healthchecks-api.
Thank you for your comments and advice. I think relying on the healthcheck is probably not the way to go. I'm going to be reevaluating.
thanks,
jas
from node-healthchecks-api.
Closing, as the issue author agreed on above clarifications.
from node-healthchecks-api.
Related Issues (20)
- An in-range update of nock is breaking the build 🚨 HOT 5
- An in-range update of eslint-plugin-jest is breaking the build 🚨 HOT 4
- An in-range update of eslint-plugin-jest is breaking the build 🚨 HOT 4
- An in-range update of eslint-plugin-jsdoc is breaking the build 🚨 HOT 6
- An in-range update of eslint is breaking the build 🚨 HOT 1
- An in-range update of http-status is breaking the build 🚨 HOT 4
- An in-range update of eslint-plugin-jsdoc is breaking the build 🚨 HOT 6
- An in-range update of eslint-plugin-jest is breaking the build 🚨 HOT 31
- Is there is any way to use sslCa in mongo health check?? HOT 2
- An in-range update of mongodb is breaking the build 🚨 HOT 9
- An in-range update of superagent is breaking the build 🚨 HOT 3
- An in-range update of semantic-release is breaking the build 🚨 HOT 1
- An in-range update of mime-types is breaking the build 🚨 HOT 2
- An in-range update of elasticsearch is breaking the build 🚨 HOT 3
- Add mssql check type
- Add framework adapter to koa
- https check
- Invalid regular expression: /^\\status\\(?:([^\\/]+?))\\/?$/: Unmatched ')' HOT 1
- An in-range update of eslint-plugin-jest is breaking the build 🚨 HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-healthchecks-api.