Merge branch 'healthservice' into 'main'
extract health to module See merge request v3/service/configuration!18
This commit is contained in:
commit
a4a236b10e
|
@ -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: [],
|
||||||
|
|
13
src/main.ts
13
src/main.ts
|
@ -9,11 +9,14 @@ async function bootstrap() {
|
||||||
{
|
{
|
||||||
transport: Transport.GRPC,
|
transport: Transport.GRPC,
|
||||||
options: {
|
options: {
|
||||||
package: 'configuration',
|
package: ['configuration', 'health'],
|
||||||
protoPath: join(
|
protoPath: [
|
||||||
__dirname,
|
join(
|
||||||
'modules/configuration/adapters/primaries/configuration.proto',
|
__dirname,
|
||||||
),
|
'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 },
|
||||||
},
|
},
|
||||||
|
|
|
@ -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,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { HealthController } from './adapters/primaries/health.controller';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
controllers: [HealthController],
|
||||||
|
})
|
||||||
|
export class HealthModule {}
|
Loading…
Reference in New Issue