extract health to module

This commit is contained in:
sbriat 2023-03-31 10:20:15 +02:00
parent d3c222d46a
commit fa0c30b335
5 changed files with 65 additions and 5 deletions

View File

@ -3,12 +3,14 @@ import { AutomapperModule } from '@automapper/nestjs';
import { Module } from '@nestjs/common'; import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config'; import { ConfigModule } from '@nestjs/config';
import { ConfigurationModule } from './modules/configuration/configuration.module'; import { ConfigurationModule } from './modules/configuration/configuration.module';
import { HealthModule } from './modules/health/health.module';
@Module({ @Module({
imports: [ imports: [
ConfigModule.forRoot({ isGlobal: true }), ConfigModule.forRoot({ isGlobal: true }),
AutomapperModule.forRoot({ strategyInitializer: classes() }), AutomapperModule.forRoot({ strategyInitializer: classes() }),
ConfigurationModule, ConfigurationModule,
HealthModule,
], ],
controllers: [], controllers: [],
providers: [], providers: [],

View File

@ -9,11 +9,14 @@ async function bootstrap() {
{ {
transport: Transport.GRPC, transport: Transport.GRPC,
options: { options: {
package: 'configuration', package: ['configuration', 'health'],
protoPath: join( protoPath: [
join(
__dirname, __dirname,
'modules/configuration/adapters/primaries/configuration.proto', 'modules/configuration/adapters/primaries/configuration.proto',
), ),
join(__dirname, 'modules/health/adapters/primaries/health.proto'),
],
url: process.env.SERVICE_URL + ':' + process.env.SERVICE_PORT, url: process.env.SERVICE_URL + ':' + process.env.SERVICE_PORT,
loader: { keepCase: true }, loader: { keepCase: true },
}, },

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

@ -0,0 +1,21 @@
syntax = "proto3";
package health;
service Health {
rpc Check(HealthCheckRequest) returns (HealthCheckResponse);
}
message HealthCheckRequest {
string service = 1;
}
message HealthCheckResponse {
enum ServingStatus {
UNKNOWN = 0;
SERVING = 1;
NOT_SERVING = 2;
}
ServingStatus status = 1;
}

View File

@ -0,0 +1,7 @@
import { Module } from '@nestjs/common';
import { HealthController } from './adapters/primaries/health.controller';
@Module({
controllers: [HealthController],
})
export class HealthModule {}