import { Injectable } from '@nestjs/common'; import { AppLogger } from '../../../logger'; import { getConnectionManager } from 'typeorm'; import { HealthCheckError } from '@godaddy/terminus'; import { HealthIndicator, HealthIndicatorResult } from '@nestjs/terminus'; import { TypeOrmSQLConfigService } from '../../../database'; @Injectable() export class PostgresHealthIndicator extends HealthIndicator { protected TAG: string = `${this.constructor.name}`; constructor() { super(); AppLogger.log('Init', this.TAG); } public async isHealthy(key: string): Promise { try { const connectionManager = await getConnectionManager().get(TypeOrmSQLConfigService.SQL_CONNECTION_NAME); await connectionManager.query(`select * from pg_stat_activity`); return this.getStatus(key, true); } catch (error) { AppLogger.error(error, this.TAG); throw new HealthCheckError(this.TAG + ' Health failed', error); } } }