inceptum
Version:
hipages take on the foundational library for enterprise-grade apps written in NodeJS
73 lines • 3.13 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
const Decorators_1 = require("../ioc/Decorators");
const AdminPortPlugin_1 = require("../web/AdminPortPlugin");
const LogManager_1 = require("../log/LogManager");
const HealthCheck_1 = require("./HealthCheck");
const ContextReadyHealthCheck_1 = require("./ContextReadyHealthCheck");
const logger = LogManager_1.LogManager.getLogger(__filename);
let HealthCheckManager = class HealthCheckManager extends HealthCheck_1.HealthCheckGroup {
constructor() {
super(...arguments);
this.healthChecksToRegister = [];
}
start() {
this.healthChecksToRegister.forEach((healthCheck) => {
logger.debug(`Registering health check: ${healthCheck.getCheckName()}`);
this.addCheck(healthCheck);
});
super.start();
}
stop() {
super.stop();
}
};
__decorate([
Decorators_1.AutowireGroup(HealthCheck_1.HEALTH_CHECK_GROUP)
], HealthCheckManager.prototype, "healthChecksToRegister", void 0);
__decorate([
Decorators_1.StartMethod
], HealthCheckManager.prototype, "start", null);
__decorate([
Decorators_1.StopMethod
], HealthCheckManager.prototype, "stop", null);
HealthCheckManager = __decorate([
Decorators_1.Lazy(false)
], HealthCheckManager);
exports.HealthCheckManager = HealthCheckManager;
class HealthCheckPlugin {
constructor() {
this.name = 'HealthCheckPlugin';
}
getName() {
return this.name;
}
willStart(app, pluginContext) {
const context = app.getContext();
context.registerSingletons(HealthCheckManager, ContextReadyHealthCheck_1.ContextReadyHealthCheck);
}
didStart(app, pluginContext) {
const context = app.getContext();
const express = pluginContext.get(AdminPortPlugin_1.default.CONTEXT_APP_KEY);
if (express) {
express.get('/health', async (req, res) => {
const healthCheckManager = await context.getObjectByName('HealthCheckManager');
const healthCheckResult = healthCheckManager.getLastResult();
if (healthCheckResult.status === HealthCheck_1.HealthCheckStatus.OK || healthCheckResult.status === HealthCheck_1.HealthCheckStatus.NOT_READY) {
res.send(healthCheckResult);
}
else {
res.status(503).send(healthCheckResult);
}
});
}
}
}
exports.default = HealthCheckPlugin;
//# sourceMappingURL=HealthCheckPlugin.js.map