From ce6a05ab66f42a132acbcf09c9bc4767f589837a Mon Sep 17 00:00:00 2001 From: Will H Date: Fri, 5 Jul 2024 13:40:51 +1200 Subject: [PATCH] cr - add redis check and logging --- .../integrations/health/health.controller.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/apps/server/src/integrations/health/health.controller.ts b/apps/server/src/integrations/health/health.controller.ts index 65e28852..c9dd9acb 100644 --- a/apps/server/src/integrations/health/health.controller.ts +++ b/apps/server/src/integrations/health/health.controller.ts @@ -5,22 +5,33 @@ import { HttpCode, HttpStatus, InternalServerErrorException, - Post, + Logger, } from '@nestjs/common'; import { sql } from 'kysely'; import { InjectKysely } from 'nestjs-kysely'; +import { Redis } from 'ioredis'; +import { EnvironmentService } from '../environment/environment.service'; @Controller() export class HealthController { - constructor(@InjectKysely() private readonly db: KyselyDB) {} + constructor( + @InjectKysely() private readonly db: KyselyDB, + private environmentService: EnvironmentService, + ) {} + + private readonly logger = new Logger(HealthController.name); @Get('health') @HttpCode(HttpStatus.OK) async health() { try { + const redis = new Redis(this.environmentService.getRedisUrl()); + await sql`SELECT 1=1`.execute(this.db); + await redis.ping(); } catch (error) { - throw new InternalServerErrorException('Health check failed'); + this.logger.error('Health check failed'); + throw new InternalServerErrorException(); } } }