egg-healthy
Version:
Liveness and Readiness health check for egg application
27 lines (20 loc) • 531 B
JavaScript
;
module.exports = class Lifecycle {
constructor(app) {
this.app = app;
this.serverHealthStatus = app.serverHealthStatus;
}
configDidLoad() {
this.app.config.coreMiddleware.unshift('eggHealthy');
}
async serverDidReady() {
this.serverHealthStatus.up();
}
async didReady(err) {
// it should be run before all `beforeClose` handler
this.app.lifecycle.registerBeforeClose(() => {
this.serverHealthStatus.stop();
});
if (err) this.serverHealthStatus.down();
}
};