matcher/old/modules/health/adapters/primaries/health-server.controller.ts

43 lines
1.1 KiB
TypeScript
Raw Normal View History

2023-04-06 12:21:43 +00:00
import { Controller } from '@nestjs/common';
import { GrpcMethod } from '@nestjs/microservices';
2023-08-16 10:28:20 +00:00
import { RepositoriesHealthIndicatorUseCase } from '../../domain/usecases/repositories.health-indicator.usecase';
2023-04-06 12:21:43 +00:00
enum ServingStatus {
UNKNOWN = 0,
SERVING = 1,
NOT_SERVING = 2,
}
interface HealthCheckRequest {
service: string;
}
interface HealthCheckResponse {
status: ServingStatus;
}
@Controller()
export class HealthServerController {
constructor(
2023-08-16 10:28:20 +00:00
private readonly repositoriesHealthIndicatorUseCase: RepositoriesHealthIndicatorUseCase,
2023-04-06 12:21:43 +00:00
) {}
@GrpcMethod('Health', 'Check')
async check(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
data: HealthCheckRequest,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
metadata: any,
): Promise<HealthCheckResponse> {
2023-08-16 10:28:20 +00:00
const healthCheck = await this.repositoriesHealthIndicatorUseCase.isHealthy(
'repositories',
2023-04-06 12:21:43 +00:00
);
return {
status:
2023-08-16 10:28:20 +00:00
healthCheck['repositories'].status == 'up'
2023-04-06 12:21:43 +00:00
? ServingStatus.SERVING
: ServingStatus.NOT_SERVING,
};
}
}