From da2e3654558a606df7b508077dca5ce6b54b7e36 Mon Sep 17 00:00:00 2001 From: sbriat Date: Fri, 31 Mar 2023 10:10:31 +0200 Subject: [PATCH] extract health to module --- src/app.module.ts | 2 ++ src/main.ts | 10 ++++----- .../adapters/primaries/health.controller.ts | 0 .../health/adapters/primaries/health.proto | 21 +++++++++++++++++++ src/modules/health/health.module.ts | 7 +++++++ .../users/adapters/primaries/user.proto | 17 --------------- src/modules/users/users.module.ts | 3 +-- 7 files changed, 36 insertions(+), 24 deletions(-) rename src/modules/{users => health}/adapters/primaries/health.controller.ts (100%) create mode 100644 src/modules/health/adapters/primaries/health.proto create mode 100644 src/modules/health/health.module.ts diff --git a/src/app.module.ts b/src/app.module.ts index ce77035..1ae5ffc 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -3,6 +3,7 @@ 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'; import { UsersModule } from './modules/users/users.module'; @Module({ @@ -11,6 +12,7 @@ import { UsersModule } from './modules/users/users.module'; AutomapperModule.forRoot({ strategyInitializer: classes() }), UsersModule, ConfigurationModule, + HealthModule, ], controllers: [], providers: [], diff --git a/src/main.ts b/src/main.ts index 7673cd1..89f98fc 100644 --- a/src/main.ts +++ b/src/main.ts @@ -9,11 +9,11 @@ async function bootstrap() { { transport: Transport.GRPC, options: { - package: 'user', - protoPath: join( - __dirname, - 'modules/users/adapters/primaries/user.proto', - ), + package: ['user', 'health'], + protoPath: [ + join(__dirname, 'modules/users/adapters/primaries/user.proto'), + join(__dirname, 'modules/health/adapters/primaries/health.proto'), + ], url: process.env.SERVICE_URL + ':' + process.env.SERVICE_PORT, loader: { keepCase: true }, }, diff --git a/src/modules/users/adapters/primaries/health.controller.ts b/src/modules/health/adapters/primaries/health.controller.ts similarity index 100% rename from src/modules/users/adapters/primaries/health.controller.ts rename to src/modules/health/adapters/primaries/health.controller.ts diff --git a/src/modules/health/adapters/primaries/health.proto b/src/modules/health/adapters/primaries/health.proto new file mode 100644 index 0000000..74e1a4c --- /dev/null +++ b/src/modules/health/adapters/primaries/health.proto @@ -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; +} diff --git a/src/modules/health/health.module.ts b/src/modules/health/health.module.ts new file mode 100644 index 0000000..1f715d5 --- /dev/null +++ b/src/modules/health/health.module.ts @@ -0,0 +1,7 @@ +import { Module } from '@nestjs/common'; +import { HealthController } from './adapters/primaries/health.controller'; + +@Module({ + controllers: [HealthController], +}) +export class HealthModule {} diff --git a/src/modules/users/adapters/primaries/user.proto b/src/modules/users/adapters/primaries/user.proto index 0a629d6..a579285 100644 --- a/src/modules/users/adapters/primaries/user.proto +++ b/src/modules/users/adapters/primaries/user.proto @@ -33,20 +33,3 @@ message Users { } message Empty {} - -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; -} diff --git a/src/modules/users/users.module.ts b/src/modules/users/users.module.ts index 8aa70e3..736077e 100644 --- a/src/modules/users/users.module.ts +++ b/src/modules/users/users.module.ts @@ -5,7 +5,6 @@ import { ConfigModule, ConfigService } from '@nestjs/config'; import { CqrsModule } from '@nestjs/cqrs'; import { redisStore } from 'cache-manager-ioredis-yet'; import { DatabaseModule } from '../database/database.module'; -import { HealthController } from './adapters/primaries/health.controller'; import { UsersController } from './adapters/primaries/users.controller'; import { Messager } from './adapters/secondaries/messager'; import { UsersRepository } from './adapters/secondaries/users.repository'; @@ -47,7 +46,7 @@ import { UserProfile } from './mappers/user.profile'; inject: [ConfigService], }), ], - controllers: [UsersController, HealthController], + controllers: [UsersController], providers: [ UserProfile, UsersRepository,