UNPKG

@amirmarmul/waba-common

Version:

![GitHub release](https://img.shields.io/github/v/release/amirmarmul/waba-common?style=flat-square)

49 lines (48 loc) 2.08 kB
"use strict"; 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.HealthCheckExecutor = void 0; const Container_1 = require("../../../../../core/infrastructure/Container"); let HealthCheckExecutor = class HealthCheckExecutor { async execute(healthIndicators) { const { results, errors } = await this.executeHealthIndicators(healthIndicators); return await this.getResults(results, errors); } async executeHealthIndicators(healthIndicators) { const results = []; const errors = []; const result = await Promise.allSettled(healthIndicators.map(async (h) => h())); result.forEach((res) => { if (res.status === 'fulfilled') { results.push(res.value); } else { const error = res.reason; errors.push(error); } }); return { results, errors }; } async getResults(results, errors) { const infoErrorCombained = results.concat(errors); const details = this.getSummary(infoErrorCombained); let status = 'ok'; status = errors.length > 0 ? 'error' : status; return { status, details }; } getSummary(results) { return results.reduce((prev, curr) => Object.assign(prev, curr), {}); } }; HealthCheckExecutor = __decorate([ (0, Container_1.Service)() ], HealthCheckExecutor); exports.HealthCheckExecutor = HealthCheckExecutor;