UNPKG

@atomist/automation-client

Version:

Atomist API for software low-level client

57 lines 1.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** * Enum value expressing the state of a health check. */ var HealthStatus; (function (HealthStatus) { HealthStatus["Up"] = "UP"; HealthStatus["Down"] = "DOWN"; HealthStatus["OutOfService"] = "OUT_OF_SERVICE"; })(HealthStatus = exports.HealthStatus || (exports.HealthStatus = {})); /** * Register a HealthIndicator at startup. * @param {HealthIndicator} indicator */ function registerHealthIndicator(indicator) { exports.Indicators.push(indicator); } exports.registerHealthIndicator = registerHealthIndicator; /** * Returns the combined health of the client. * @returns {Health<any>} */ function health() { return CompositeHealthIndicator(exports.Indicators); } exports.health = health; // public for testing only exports.Indicators = []; const CompositeHealthIndicator = (indicators) => { if (indicators.length === 1) { return indicators[0](); } else if (indicators.length === 0) { return { status: HealthStatus.Up, detail: "Service is up", }; } const status = indicators.map(h => h().status).reduce((p, c) => { if (p === HealthStatus.Down) { return p; } if (p === HealthStatus.OutOfService && c === HealthStatus.Down) { return c; } if (p === HealthStatus.Up) { return c; } return p; }, HealthStatus.Up); return { status, detail: indicators.map(i => i()), }; }; //# sourceMappingURL=health.js.map