Merge branch 'improveHealth' into 'main'

improve healthcheck service

See merge request v3/service/auth!28
This commit is contained in:
Sylvain Briat 2023-03-30 15:40:46 +00:00
commit f08622ce35
3 changed files with 33 additions and 14 deletions

View File

@ -24,12 +24,6 @@ import { AuthenticationPresenter } from './authentication.presenter';
import { RpcValidationPipe } from '../../../../utils/pipes/rpc.validation-pipe'; import { RpcValidationPipe } from '../../../../utils/pipes/rpc.validation-pipe';
import { UsernamePresenter } from './username.presenter'; import { UsernamePresenter } from './username.presenter';
enum ServingStatus {
UNKNOWN = 0,
SERVING = 1,
NOT_SERVING = 2,
}
@UsePipes( @UsePipes(
new RpcValidationPipe({ new RpcValidationPipe({
whitelist: true, whitelist: true,
@ -191,11 +185,4 @@ export class AuthenticationController {
}); });
} }
} }
@GrpcMethod('Health', 'Check')
async check(): Promise<{ status: ServingStatus }> {
return {
status: ServingStatus.SERVING,
};
}
} }

View File

@ -0,0 +1,27 @@
import { Controller } from '@nestjs/common';
import { GrpcMethod } from '@nestjs/microservices';
enum ServingStatus {
UNKNOWN = 0,
SERVING = 1,
NOT_SERVING = 2,
}
interface HealthCheckRequest {
service: string;
}
interface HealthCheckResponse {
status: ServingStatus;
}
@Controller()
export class HealthController {
@GrpcMethod('Health', 'Check')
// eslint-disable-next-line @typescript-eslint/no-unused-vars
check(data: HealthCheckRequest, metadata: any): HealthCheckResponse {
return {
status: ServingStatus.SERVING,
};
}
}

View File

@ -16,6 +16,7 @@ import { RabbitMQModule } from '@golevelup/nestjs-rabbitmq';
import { ConfigModule, ConfigService } from '@nestjs/config'; import { ConfigModule, ConfigService } from '@nestjs/config';
import { AuthenticationMessagerController } from './adapters/primaries/authentication-messager.controller'; import { AuthenticationMessagerController } from './adapters/primaries/authentication-messager.controller';
import { Messager } from './adapters/secondaries/messager'; import { Messager } from './adapters/secondaries/messager';
import { HealthController } from './adapters/primaries/health.controller';
@Module({ @Module({
imports: [ imports: [
@ -47,7 +48,11 @@ import { Messager } from './adapters/secondaries/messager';
inject: [ConfigService], inject: [ConfigService],
}), }),
], ],
controllers: [AuthenticationController, AuthenticationMessagerController], controllers: [
AuthenticationController,
AuthenticationMessagerController,
HealthController,
],
providers: [ providers: [
AuthenticationProfile, AuthenticationProfile,
UsernameProfile, UsernameProfile,