diff --git a/apiv2/src/App.module.ts b/apiv2/src/App.module.ts index 700874cf79..7d8c1d6ea7 100644 --- a/apiv2/src/App.module.ts +++ b/apiv2/src/App.module.ts @@ -1,13 +1,12 @@ -import { Global, Logger, MiddlewareConsumer, Module } from "@nestjs/common"; -import configuration from "./config/configuration"; +import { Logger, MiddlewareConsumer, Module } from "@nestjs/common"; import { ConfigModule } from "@nestjs/config"; import { SentryModule } from "@sentry/nestjs/setup"; +import configuration from "./config/configuration"; +import { QueueModule } from "@infra/Queue.module"; import { AdminModule } from "./admin/Admin.module"; -import { LoggerRequestMiddleware } from "./shared/infra/LoggerRequest.middleware"; import { CorrelationIdMiddleware } from "./shared/infra/CorrelationId.middleware.js"; -import { SharedModule } from "./shared/Shared.module"; -import { TaskModule } from "./task/Task.module"; +import { LoggerRequestMiddleware } from "./shared/infra/LoggerRequest.middleware"; @Module({ imports: [ @@ -16,6 +15,7 @@ import { TaskModule } from "./task/Task.module"; }), SentryModule.forRoot(), AdminModule, + QueueModule, ], controllers: [], providers: [Logger], diff --git a/apiv2/src/MainJob.module.ts b/apiv2/src/MainJob.module.ts new file mode 100644 index 0000000000..bfaa796367 --- /dev/null +++ b/apiv2/src/MainJob.module.ts @@ -0,0 +1,11 @@ +import { Module } from "@nestjs/common"; +import { NotificationJobModule } from "@notification/NotificationJob.module"; +import { AdminJobModule } from "./admin/AdminJob.module"; +import configuration from "@config/configuration"; +import { ConfigModule } from "@nestjs/config"; +import { QueueModule } from "@infra/Queue.module"; + +@Module({ + imports: [QueueModule, NotificationJobModule, AdminJobModule], +}) +export class MainJobModule {} diff --git a/apiv2/src/admin/Admin.module.ts b/apiv2/src/admin/Admin.module.ts index d548b028bc..0aecdb2da0 100644 --- a/apiv2/src/admin/Admin.module.ts +++ b/apiv2/src/admin/Admin.module.ts @@ -29,25 +29,10 @@ import { AdminTaskRepository } from "./infra/task/AdminTaskMongo.repository"; import { QueueType } from "@shared/infra/Queue"; import { taskMongoProviders } from "@task/infra/TaskMongo.provider"; import { AdminTaskController } from "./infra/task/api/AdminTask.controller"; +import { QueueModule } from "@infra/Queue.module"; @Module({ - imports: [ - ClsModule.forRoot({}), - ConfigModule, - DatabaseModule, //TO REMOVE ? - JwtAuthModule, - NotificationModule, - BullModule.registerQueue({ - name: NotificationQueueType.EMAIL, - }), - BullModule.registerQueue({ - name: NotificationQueueType.CONTACT, - }), - BullModule.registerQueue({ - name: QueueType.ADMIN_TASK, - }), - TaskModule, - ], + imports: [ClsModule.forRoot({}), DatabaseModule, JwtAuthModule, NotificationModule, QueueModule, TaskModule], controllers: [ClasseController, AuthController, AdminTaskController], providers: [ ClasseService, diff --git a/apiv2/src/admin/AdminJob.module.ts b/apiv2/src/admin/AdminJob.module.ts index a82ed89e76..8b5806f96d 100644 --- a/apiv2/src/admin/AdminJob.module.ts +++ b/apiv2/src/admin/AdminJob.module.ts @@ -1,27 +1,15 @@ -import { Logger, Module } from "@nestjs/common"; -import { AdminTaskConsumer } from "./infra/task/AdminTask.consumer"; -import { AdminTaskRepository } from "./infra/task/AdminTaskMongo.repository"; import configuration from "@config/configuration"; +import { DatabaseModule } from "@infra/Database.module"; import { QueueModule } from "@infra/Queue.module"; +import { Logger, Module } from "@nestjs/common"; import { ConfigModule } from "@nestjs/config"; -import { DatabaseModule } from "@infra/Database.module"; import { TaskModule } from "@task/Task.module"; import { taskMongoProviders } from "@task/infra/TaskMongo.provider"; -import { BullModule } from "@nestjs/bullmq"; -import { QueueType } from "@shared/infra/Queue"; +import { AdminTaskConsumer } from "./infra/task/AdminTask.consumer"; +import { AdminTaskRepository } from "./infra/task/AdminTaskMongo.repository"; @Module({ - imports: [ - TaskModule, - DatabaseModule, - ConfigModule.forRoot({ - load: [configuration], - }), - QueueModule, - BullModule.registerQueue({ - name: QueueType.ADMIN_TASK, - }), - ], + imports: [TaskModule, DatabaseModule], providers: [ Logger, AdminTaskConsumer, diff --git a/apiv2/src/infra/Queue.module.ts b/apiv2/src/infra/Queue.module.ts index 1e39461960..012f0a0eb1 100644 --- a/apiv2/src/infra/Queue.module.ts +++ b/apiv2/src/infra/Queue.module.ts @@ -1,10 +1,11 @@ import { ConfigModule, ConfigService } from "@nestjs/config"; import { BullModule } from "@nestjs/bullmq"; -import { Module } from "@nestjs/common"; +import { Global, Module } from "@nestjs/common"; import { NotificationQueueType } from "@notification/infra/Notification"; import { QueueType } from "@shared/infra/Queue"; +@Global() @Module({ imports: [ BullModule.forRootAsync({ @@ -22,6 +23,9 @@ import { QueueType } from "@shared/infra/Queue"; BullModule.registerQueue({ name: NotificationQueueType.CONTACT, }), + BullModule.registerQueue({ + name: QueueType.ADMIN_TASK, + }), ], exports: [BullModule], }) diff --git a/apiv2/src/main.ts b/apiv2/src/main.ts index 483d73f37f..40f5472e08 100644 --- a/apiv2/src/main.ts +++ b/apiv2/src/main.ts @@ -4,7 +4,6 @@ import { ConfigService } from "@nestjs/config"; import { ValidationPipe } from "@nestjs/common"; import { NestFactory } from "@nestjs/core"; import { AppModule } from "./App.module"; -import { NotificationJobModule } from "./notification/NotificationJob.module"; async function bootstrap() { const app = await NestFactory.create(AppModule); diff --git a/apiv2/src/mainJob.ts b/apiv2/src/mainJob.ts index 427dd917fb..b62e23dc3b 100644 --- a/apiv2/src/mainJob.ts +++ b/apiv2/src/mainJob.ts @@ -1,13 +1,11 @@ import "./instrument"; // first -import { NestFactory } from "@nestjs/core"; -import { NotificationJobModule } from "./notification/NotificationJob.module"; import { Logger } from "@nestjs/common"; -import { AdminJobModule } from "./admin/AdminJob.module"; +import { NestFactory } from "@nestjs/core"; +import { MainJobModule } from "./MainJob.module"; async function bootstrap() { - await NestFactory.createApplicationContext(NotificationJobModule); - await NestFactory.createApplicationContext(AdminJobModule); + await NestFactory.createApplicationContext(MainJobModule); Logger.log(`Job started`, "bootstrap mainJob"); // TODO: handle logs error here ? // process.on("uncaughtException", (error) => { diff --git a/apiv2/src/notification/Notification.module.ts b/apiv2/src/notification/Notification.module.ts index 080f33364b..f17c706892 100644 --- a/apiv2/src/notification/Notification.module.ts +++ b/apiv2/src/notification/Notification.module.ts @@ -9,7 +9,7 @@ import { ContactProducer } from "./infra/email/Contact.producer"; import { NotificationProducer } from "./infra/Notification.producer"; @Module({ - imports: [QueueModule, SharedModule], + imports: [SharedModule], providers: [ { provide: NotificationGateway, diff --git a/apiv2/src/notification/NotificationJob.module.ts b/apiv2/src/notification/NotificationJob.module.ts index 8d44b11759..d2c9a102ae 100644 --- a/apiv2/src/notification/NotificationJob.module.ts +++ b/apiv2/src/notification/NotificationJob.module.ts @@ -11,7 +11,6 @@ import { contactFactory, emailFactory } from "./infra/email/brevo/EmailContact.f ConfigModule.forRoot({ load: [configuration], }), - QueueModule, ], providers: [Logger, EmailConsumer, ContactConsumer, emailFactory, contactFactory], }) diff --git a/apiv2/src/task/infra/TaskMongo.repository.ts b/apiv2/src/task/infra/TaskMongo.repository.ts index df95e8c81c..54f47ef310 100644 --- a/apiv2/src/task/infra/TaskMongo.repository.ts +++ b/apiv2/src/task/infra/TaskMongo.repository.ts @@ -47,7 +47,6 @@ export class TaskRepository implements TaskGateway { } async toSuccess(id: string): Promise { - // TODO: check if task exists and is in progress const updatedTask = await this.taskMongooseEntity.findByIdAndUpdate( id, { status: TaskStatus.COMPLETED },