inceptum
Version:
hipages take on the foundational library for enterprise-grade apps written in NodeJS
52 lines • 2.49 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 });
exports.RabbitmqHealthCheck = void 0;
const HealthCheck_1 = require("../health/HealthCheck");
const LogManager_1 = require("../log/LogManager");
const Decorators_1 = require("../ioc/Decorators");
const logger = LogManager_1.LogManager.getLogger(__filename);
let RabbitmqHealthCheck = class RabbitmqHealthCheck extends HealthCheck_1.HealthCheck {
constructor(name) {
super(name, 60000, 2, true);
this.logger = logger;
}
async doCheck() {
if (!this.rabbitmqMgtHttpApi) {
return new HealthCheck_1.HealthCheckResult(HealthCheck_1.HealthCheckStatus.NOT_READY, 'Rabbitmq Management Http API not set yet');
}
// tslint:disable-next-line
if (this.rabbitmqMgtHttpApi.rabbitmqConfig.healthCheckEnabled === false) {
return new HealthCheck_1.HealthCheckResult(HealthCheck_1.HealthCheckStatus.OK, 'Health check DISABLED');
}
try {
const res = await this.rabbitmqMgtHttpApi.ping();
if (res.status.toUpperCase() === HealthCheck_1.HealthCheckStatus.OK) {
return new HealthCheck_1.HealthCheckResult(HealthCheck_1.HealthCheckStatus.OK, 'Ping OK');
}
else {
return new HealthCheck_1.HealthCheckResult(HealthCheck_1.HealthCheckStatus.CRITICAL, res.reason);
}
}
catch (e) {
this.logger.error(e);
throw e;
}
}
getType() {
return HealthCheck_1.HealthCheckType.DEPENDENCY;
}
};
__decorate([
(0, Decorators_1.Autowire)('RabbitmqMgtHttpApi')
], RabbitmqHealthCheck.prototype, "rabbitmqMgtHttpApi", void 0);
RabbitmqHealthCheck = __decorate([
HealthCheck_1.RegisterAsHealthCheck
], RabbitmqHealthCheck);
exports.RabbitmqHealthCheck = RabbitmqHealthCheck;
//# sourceMappingURL=RabbitmqHealthCheck.js.map