Merge branch 'improveHealth' into 'main'
refactor; add health check See merge request v3/service/territory!14
This commit is contained in:
commit
2231d45546
|
@ -3,14 +3,16 @@ import { AutomapperModule } from '@automapper/nestjs';
|
|||
import { Module } from '@nestjs/common';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import { ConfigurationModule } from './modules/configuration/configuration.module';
|
||||
import { TerritoriesModule } from './modules/territories/territories.module';
|
||||
import { TerritoryModule } from './modules/territory/territory.module';
|
||||
import { HealthModule } from './modules/health/health.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
ConfigModule.forRoot({ isGlobal: true }),
|
||||
AutomapperModule.forRoot({ strategyInitializer: classes() }),
|
||||
TerritoriesModule,
|
||||
TerritoryModule,
|
||||
ConfigurationModule,
|
||||
HealthModule,
|
||||
],
|
||||
controllers: [],
|
||||
providers: [],
|
||||
|
|
|
@ -9,11 +9,14 @@ async function bootstrap() {
|
|||
{
|
||||
transport: Transport.GRPC,
|
||||
options: {
|
||||
package: 'territory',
|
||||
protoPath: join(
|
||||
package: ['territory', 'health'],
|
||||
protoPath: [
|
||||
join(
|
||||
__dirname,
|
||||
'modules/territories/adapters/primaries/territory.proto',
|
||||
),
|
||||
join(__dirname, 'modules/health/adapters/primaries/health.proto'),
|
||||
],
|
||||
url: process.env.SERVICE_URL + ':' + process.env.SERVICE_PORT,
|
||||
loader: { keepCase: true },
|
||||
},
|
||||
|
|
|
@ -2,7 +2,7 @@ import { PrismaRepository } from '../adapters/secondaries/prisma-repository.abst
|
|||
import { ICollection } from '../interfaces/collection.interface';
|
||||
import { Point } from './point.type';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { Territory } from 'src/modules/territories/domain/entities/territory';
|
||||
import { Territory } from 'src/modules/territory/domain/entities/territory';
|
||||
import { DatabaseException } from '../exceptions/database.exception';
|
||||
|
||||
export class TerritoryRepository<T> extends PrismaRepository<T> {
|
|
@ -2,8 +2,8 @@ import { Injectable } from '@nestjs/common';
|
|||
import { Test, TestingModule } from '@nestjs/testing';
|
||||
import { PrismaService } from '../../src/adapters/secondaries/prisma-service';
|
||||
import { TerritoryRepository } from '../../src/domain/territory-repository';
|
||||
import { Territory } from '../../../territories/domain/entities/territory';
|
||||
import { Point } from '../../../territories/domain/entities/point';
|
||||
import { Territory } from '../../../territory/domain/entities/territory';
|
||||
import { Point } from '../../../territory/domain/entities/point';
|
||||
import { DatabaseException } from '../../src/exceptions/database.exception';
|
||||
|
||||
const mockTerritories: Array<Territory> = [
|
|
@ -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 {}
|
|
@ -6,7 +6,7 @@ import { GrpcMethod, RpcException } from '@nestjs/microservices';
|
|||
import { Territory } from '../../domain/entities/territory';
|
||||
import { FindAllTerritoriesForPointQuery } from '../../queries/find-all-territories-for-point.query';
|
||||
import { TerritoryPresenter } from './territory.presenter';
|
||||
import { ICollection } from '../../../database/src/interfaces/collection.interface';
|
||||
import { ICollection } from '../../../databases/src/interfaces/collection.interface';
|
||||
import { RpcValidationPipe } from '../../../../utils/pipes/rpc.validation-pipe';
|
||||
import { FindAllTerritoriesForPointRequest } from '../../domain/dtos/find-all-territories-for-point.request';
|
||||
import { FindAllTerritoriesRequest } from '../../domain/dtos/find-all-territories.request';
|
||||
|
@ -15,7 +15,7 @@ import { FindTerritoryByUuidRequest } from '../../domain/dtos/find-territory-by-
|
|||
import { FindTerritoryByUuidQuery } from '../../queries/find-territory-by-uuid.query';
|
||||
import { CreateTerritoryRequest } from '../../domain/dtos/create-territory.request';
|
||||
import { CreateTerritoryCommand } from '../../commands/create-territory.command';
|
||||
import { DatabaseException } from 'src/modules/database/src/exceptions/database.exception';
|
||||
import { DatabaseException } from 'src/modules/databases/src/exceptions/database.exception';
|
||||
import { UpdateTerritoryRequest } from '../../domain/dtos/update-territory.request';
|
||||
import { UpdateTerritoryCommand } from '../../commands/update-territory.command';
|
||||
import { DeleteTerritoryCommand } from '../../commands/delete-territory.command';
|
||||
|
@ -29,7 +29,7 @@ import { FindAllTerritoriesForPointsQuery } from '../../queries/find-all-territo
|
|||
}),
|
||||
)
|
||||
@Controller()
|
||||
export class TerritoriesController {
|
||||
export class TerritoryController {
|
||||
constructor(
|
||||
private readonly _commandBus: CommandBus,
|
||||
private readonly _queryBus: QueryBus,
|
|
@ -1,5 +1,5 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { TerritoryRepository } from '../../../database/src/domain/territory-repository';
|
||||
import { TerritoryRepository } from '../../../databases/src/domain/territory-repository';
|
||||
import { Territory } from '../../domain/entities/territory';
|
||||
|
||||
@Injectable()
|
|
@ -1,5 +1,5 @@
|
|||
import { QueryHandler } from '@nestjs/cqrs';
|
||||
import { ICollection } from 'src/modules/database/src/interfaces/collection.interface';
|
||||
import { ICollection } from 'src/modules/databases/src/interfaces/collection.interface';
|
||||
import { TerritoriesRepository } from '../../adapters/secondaries/territories.repository';
|
||||
import { FindAllTerritoriesForPointQuery } from '../../queries/find-all-territories-for-point.query';
|
||||
import { Territory } from '../entities/territory';
|
|
@ -1,5 +1,5 @@
|
|||
import { QueryHandler } from '@nestjs/cqrs';
|
||||
import { ICollection } from 'src/modules/database/src/interfaces/collection.interface';
|
||||
import { ICollection } from 'src/modules/databases/src/interfaces/collection.interface';
|
||||
import { TerritoriesRepository } from '../../adapters/secondaries/territories.repository';
|
||||
import { FindAllTerritoriesForPointsQuery } from '../../queries/find-all-territories-for-points.query';
|
||||
import { Territory } from '../entities/territory';
|
|
@ -1,5 +1,5 @@
|
|||
import { QueryHandler } from '@nestjs/cqrs';
|
||||
import { ICollection } from 'src/modules/database/src/interfaces/collection.interface';
|
||||
import { ICollection } from 'src/modules/databases/src/interfaces/collection.interface';
|
||||
import { TerritoriesRepository } from '../../adapters/secondaries/territories.repository';
|
||||
import { FindAllTerritoriesQuery } from '../../queries/find-all-territories.query';
|
||||
import { Territory } from '../entities/territory';
|
|
@ -4,8 +4,8 @@ import { CacheModule, Module } from '@nestjs/common';
|
|||
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 { TerritoriesController } from './adapters/primaries/territories.controller';
|
||||
import { DatabaseModule } from '../databases/database.module';
|
||||
import { TerritoryController } from './adapters/primaries/territory.controller';
|
||||
import { TerritoriesRepository } from './adapters/secondaries/territories.repository';
|
||||
import { Messager } from './adapters/secondaries/messager';
|
||||
import { CreateTerritoryUseCase } from './domain/usecases/create-territory.usecase';
|
||||
|
@ -48,7 +48,7 @@ import { TerritoryProfile } from './mappers/territory.profile';
|
|||
inject: [ConfigService],
|
||||
}),
|
||||
],
|
||||
controllers: [TerritoriesController],
|
||||
controllers: [TerritoryController],
|
||||
providers: [
|
||||
TerritoryProfile,
|
||||
TerritoriesRepository,
|
||||
|
@ -63,4 +63,4 @@ import { TerritoryProfile } from './mappers/territory.profile';
|
|||
],
|
||||
exports: [],
|
||||
})
|
||||
export class TerritoriesModule {}
|
||||
export class TerritoryModule {}
|
|
@ -1,7 +1,7 @@
|
|||
import { TestingModule, Test } from '@nestjs/testing';
|
||||
import { DatabaseModule } from '../../../database/database.module';
|
||||
import { PrismaService } from '../../../database/src/adapters/secondaries/prisma-service';
|
||||
import { DatabaseException } from '../../../database/src/exceptions/database.exception';
|
||||
import { DatabaseModule } from '../../../databases/database.module';
|
||||
import { PrismaService } from '../../../databases/src/adapters/secondaries/prisma-service';
|
||||
import { DatabaseException } from '../../../databases/src/exceptions/database.exception';
|
||||
import { TerritoriesRepository } from '../../adapters/secondaries/territories.repository';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { Territory } from '../../domain/entities/territory';
|
|
@ -1,5 +1,5 @@
|
|||
import { ArgumentMetadata } from '@nestjs/common';
|
||||
import { UpdateTerritoryRequest } from '../../../modules/territories/domain/dtos/update-territory.request';
|
||||
import { UpdateTerritoryRequest } from '../../../modules/territory/domain/dtos/update-territory.request';
|
||||
import { RpcValidationPipe } from '../../pipes/rpc.validation-pipe';
|
||||
|
||||
describe('RpcValidationPipe', () => {
|
||||
|
|
Loading…
Reference in New Issue