From 717046120c8879daf89b433d23a9a639e2e2765d Mon Sep 17 00:00:00 2001 From: jos3duardo Date: Mon, 11 Aug 2025 23:52:39 -0400 Subject: [PATCH] Update README.md to reflect project name and features --- .../health/enumns/service-status.enum.ts | 4 - src/modules/health/health.module.ts | 11 --- src/modules/health/services/health.service.ts | 81 ------------------- .../health/tests/health.service.spec.ts | 18 ----- 4 files changed, 114 deletions(-) delete mode 100644 src/modules/health/enumns/service-status.enum.ts delete mode 100644 src/modules/health/health.module.ts delete mode 100644 src/modules/health/services/health.service.ts delete mode 100644 src/modules/health/tests/health.service.spec.ts diff --git a/src/modules/health/enumns/service-status.enum.ts b/src/modules/health/enumns/service-status.enum.ts deleted file mode 100644 index 70d4a46..0000000 --- a/src/modules/health/enumns/service-status.enum.ts +++ /dev/null @@ -1,4 +0,0 @@ -export enum ServiceStatusEnum { - UP = 'up', - DOWN = 'down', -} diff --git a/src/modules/health/health.module.ts b/src/modules/health/health.module.ts deleted file mode 100644 index b18a3bc..0000000 --- a/src/modules/health/health.module.ts +++ /dev/null @@ -1,11 +0,0 @@ -import { Module } from '@nestjs/common'; -import { HealthService } from './services/health.service'; -import { HttpModule } from '@nestjs/axios'; -import { ScheduleModule } from '@nestjs/schedule'; - -@Module({ - imports: [HttpModule, ScheduleModule.forRoot()], - providers: [HealthService], - exports: [HealthService], -}) -export class HealthModule {} diff --git a/src/modules/health/services/health.service.ts b/src/modules/health/services/health.service.ts deleted file mode 100644 index b129462..0000000 --- a/src/modules/health/services/health.service.ts +++ /dev/null @@ -1,81 +0,0 @@ -import { Injectable, Logger } from '@nestjs/common'; -import { HttpService } from '@nestjs/axios'; -import { ConfigService } from '@nestjs/config'; -import { Cron } from '@nestjs/schedule'; -import { firstValueFrom } from 'rxjs'; -import { ServiceStatusEnum } from '../enumns/service-status.enum'; -import { ProcessorTypeEnum } from '../../payments/enumns/processor-type.enum'; - -@Injectable() -export class HealthService { - private readonly logger = new Logger(HealthService.name); - private defaultServiceStatus: ServiceStatusEnum = ServiceStatusEnum.UP; - private fallbackServiceStatus: ServiceStatusEnum = ServiceStatusEnum.UP; - - constructor( - private readonly httpService: HttpService, - private readonly configService: ConfigService, - ) {} - - @Cron('*/5 * * * * *') - async performHealthChecks() { - const defaultUrl: string = - this.configService.get('paymentProcessors.defaultUrl') ?? ''; - const fallbackUrl: string = - this.configService.get('paymentProcessors.fallbackUrl') ?? ''; - - await Promise.all([ - this.checkServiceHealth( - ProcessorTypeEnum.DEFAULT, - `${defaultUrl}/payments/service-health`, - ), - this.checkServiceHealth( - ProcessorTypeEnum.FALLBACK, - `${fallbackUrl}/payments/service-health`, - ), - ]); - } - - shouldUseDefaultProcessor(): boolean { - return this.defaultServiceStatus === ServiceStatusEnum.UP; - } - - shouldUseFallbackProcessor(): boolean { - return this.fallbackServiceStatus === ServiceStatusEnum.UP; - } - - getPreferredProcessor(): 'default' | 'fallback' | null { - if (this.shouldUseDefaultProcessor()) { - return 'default'; - } else if (this.shouldUseFallbackProcessor()) { - return 'fallback'; - } - return null; - } - - private async checkServiceHealth( - serviceName: string, - url: string, - ): Promise { - let status: ServiceStatusEnum; - - try { - const response = await firstValueFrom( - this.httpService.get(url, { - timeout: 500, - }), - ); - - status = - response.status === 200 ? ServiceStatusEnum.UP : ServiceStatusEnum.DOWN; - } catch (error) { - status = ServiceStatusEnum.DOWN; - } - - if (serviceName === 'default') { - this.defaultServiceStatus = status; - } else { - this.fallbackServiceStatus = status; - } - } -} diff --git a/src/modules/health/tests/health.service.spec.ts b/src/modules/health/tests/health.service.spec.ts deleted file mode 100644 index c89be68..0000000 --- a/src/modules/health/tests/health.service.spec.ts +++ /dev/null @@ -1,18 +0,0 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { HealthService } from '../services/health.service'; - -describe('HealthService', () => { - let service: HealthService; - - beforeEach(async () => { - const module: TestingModule = await Test.createTestingModule({ - providers: [HealthService], - }).compile(); - - service = module.get(HealthService); - }); - - it('should be defined', () => { - expect(service).toBeDefined(); - }); -});