Merge branch 'healthservice' into 'main'

extract health to module

See merge request v3/service/configuration!18
This commit is contained in:
Sylvain Briat 2023-03-31 08:28:48 +00:00
commit a4a236b10e
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 { ConfigModule } from '@nestjs/config';
import { ConfigurationModule } from './modules/configuration/configuration.module';
import { HealthModule } from './modules/health/health.module';
@Module({
imports: [
ConfigModule.forRoot({ isGlobal: true }),
AutomapperModule.forRoot({ strategyInitializer: classes() }),
ConfigurationModule,
HealthModule,
],
controllers: [],
providers: [],

View File

@ -9,11 +9,14 @@ async function bootstrap() {
{
transport: Transport.GRPC,
options: {
package: 'configuration',
protoPath: join(
__dirname,
'modules/configuration/adapters/primaries/configuration.proto',
),
package: ['configuration', 'health'],
protoPath: [
join(
__dirname,
'modules/configuration/adapters/primaries/configuration.proto',
),
join(__dirname, 'modules/health/adapters/primaries/health.proto'),
],
url: process.env.SERVICE_URL + ':' + process.env.SERVICE_PORT,
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 {}