43 lines
1.1 KiB
TypeScript
43 lines
1.1 KiB
TypeScript
import { Controller } from '@nestjs/common';
|
|
import { GrpcMethod } from '@nestjs/microservices';
|
|
import { RepositoriesHealthIndicatorUseCase } from '../../domain/usecases/repositories.health-indicator.usecase';
|
|
|
|
enum ServingStatus {
|
|
UNKNOWN = 0,
|
|
SERVING = 1,
|
|
NOT_SERVING = 2,
|
|
}
|
|
|
|
interface HealthCheckRequest {
|
|
service: string;
|
|
}
|
|
|
|
interface HealthCheckResponse {
|
|
status: ServingStatus;
|
|
}
|
|
|
|
@Controller()
|
|
export class HealthServerController {
|
|
constructor(
|
|
private readonly repositoriesHealthIndicatorUseCase: RepositoriesHealthIndicatorUseCase,
|
|
) {}
|
|
|
|
@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> {
|
|
const healthCheck = await this.repositoriesHealthIndicatorUseCase.isHealthy(
|
|
'repositories',
|
|
);
|
|
return {
|
|
status:
|
|
healthCheck['repositories'].status == 'up'
|
|
? ServingStatus.SERVING
|
|
: ServingStatus.NOT_SERVING,
|
|
};
|
|
}
|
|
}
|