cleanup indicators

This commit is contained in:
Philipinho
2024-07-05 23:05:19 +01:00
parent f12f93b373
commit a0536d852f
2 changed files with 4 additions and 18 deletions

View File

@ -17,21 +17,14 @@ export class PostgresHealthIndicator extends HealthIndicator {
} }
async pingCheck(key: string): Promise<HealthIndicatorResult> { async pingCheck(key: string): Promise<HealthIndicatorResult> {
let isHealthy = false;
try { try {
await sql`SELECT 1=1`.execute(this.db); await sql`SELECT 1=1`.execute(this.db);
isHealthy = true; return this.getStatus(key, true);
} catch (e) { } catch (e) {
this.logger.error(JSON.stringify(e)); this.logger.error(JSON.stringify(e));
}
if (isHealthy) {
return this.getStatus(key, isHealthy);
} else {
throw new HealthCheckError( throw new HealthCheckError(
`${key} is not available`, `${key} is not available`,
this.getStatus(key, isHealthy), this.getStatus(key, false),
); );
} }
} }

View File

@ -16,25 +16,18 @@ export class RedisHealthIndicator extends HealthIndicator {
} }
async pingCheck(key: string): Promise<HealthIndicatorResult> { async pingCheck(key: string): Promise<HealthIndicatorResult> {
let isHealthy = false;
try { try {
const redis = new Redis(this.environmentService.getRedisUrl(), { const redis = new Redis(this.environmentService.getRedisUrl(), {
maxRetriesPerRequest: 15, maxRetriesPerRequest: 15,
}); });
await redis.ping(); await redis.ping();
isHealthy = true; return this.getStatus(key, true);
} catch (e) { } catch (e) {
this.logger.error(e); this.logger.error(e);
}
if (isHealthy) {
return this.getStatus(key, isHealthy);
} else {
throw new HealthCheckError( throw new HealthCheckError(
`${key} is not available`, `${key} is not available`,
this.getStatus(key, isHealthy), this.getStatus(key, false),
); );
} }
} }