2023-04-06 12:21:43 +00:00
|
|
|
import { Controller } from '@nestjs/common';
|
|
|
|
import { GrpcMethod } from '@nestjs/microservices';
|
|
|
|
import { PrismaHealthIndicatorUseCase } from '../../domain/usecases/prisma.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(
|
2023-05-25 07:07:31 +00:00
|
|
|
private readonly prismaHealthIndicatorUseCase: PrismaHealthIndicatorUseCase,
|
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-05-25 07:07:31 +00:00
|
|
|
const healthCheck = await this.prismaHealthIndicatorUseCase.isHealthy(
|
2023-04-06 12:21:43 +00:00
|
|
|
'prisma',
|
|
|
|
);
|
|
|
|
return {
|
|
|
|
status:
|
|
|
|
healthCheck['prisma'].status == 'up'
|
|
|
|
? ServingStatus.SERVING
|
|
|
|
: ServingStatus.NOT_SERVING,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|