Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(repo): Simplify health indicators interface #5404

Merged
merged 3 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,4 @@ export class WSServerHealthIndicator extends HealthIndicator implements IHealthI

throw new HealthCheckError('WS server health check failed', result);
}

isActive(): Promise<HealthIndicatorResult> {
return this.isHealthy();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,4 @@ export class DalServiceHealthIndicator

throw new HealthCheckError('DAL health check failed', result);
}

isActive(): Promise<HealthIndicatorResult> {
return this.isHealthy();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@ import { HealthIndicatorResult } from '@nestjs/terminus';

export interface IHealthIndicator {
isHealthy(): Promise<HealthIndicatorResult>;
isActive(): Promise<HealthIndicatorResult>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,42 +26,17 @@ export abstract class QueueHealthIndicator
return await this.handleHealthCheck();
}

async isActive(): Promise<HealthIndicatorResult> {
return await this.handleHealthCheck(true);
}

async handleHealthCheck(checkActive = false) {
async handleHealthCheck() {
const isReady = this.queueService.isReady();
const result = this.getStatus(this.indicatorKey, isReady);

if (!isReady) {
Logger.verbose(`${this.serviceName} is not ready`, this.logContext);

throw new HealthCheckError(
`${this.serviceName} Health is not ready`,
this.getStatus(this.indicatorKey, false)
);
}

if (!checkActive) {
Logger.log(`${this.serviceName} is ready`, this.logContext);

return this.getStatus(this.indicatorKey, true);
if (isReady) {
return result;
}

const isPaused = await this.queueService.isPaused();
const isActive = isReady && !isPaused;

if (!isActive) {
Logger.log(`${this.serviceName} is not active`, this.logContext);

throw new HealthCheckError(
`${this.serviceName} Health is not active`,
this.getStatus(this.indicatorKey, false)
);
}

Logger.log(`${this.serviceName} is active`, this.logContext);

return this.getStatus(this.indicatorKey, true);
throw new HealthCheckError(
`${this.serviceName} Health is not ready`,
result
);
}
}