43 lines
1.0 KiB
TypeScript
43 lines
1.0 KiB
TypeScript
|
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(
|
||
|
private readonly _prismaHealthIndicatorUseCase: PrismaHealthIndicatorUseCase,
|
||
|
) {}
|
||
|
|
||
|
@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._prismaHealthIndicatorUseCase.isHealthy(
|
||
|
'prisma',
|
||
|
);
|
||
|
return {
|
||
|
status:
|
||
|
healthCheck['prisma'].status == 'up'
|
||
|
? ServingStatus.SERVING
|
||
|
: ServingStatus.NOT_SERVING,
|
||
|
};
|
||
|
}
|
||
|
}
|