Files
tripz-llc/backend/src/worker.module.ts
T
Hamza-AyedandClaude Opus 4.8 9bc52dbb9e fix(worker): register I18nModule and CacheModule in the worker composition root
الجيوفنس جرّ الإشعارات إلى شجرة الـworker لأول مرة، والإشعارات (و
UsersService خلفها) تحقن I18nService و CacheService. الوحدات @Global
تُسجَّل فقط إن استوردها أحد في الشجرة — وما يسجّله AppModule لا يصل
إلى جذر تجميع آخر.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-18 19:37:21 +03:00

44 lines
2.0 KiB
TypeScript

import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { TypeOrmModule } from '@nestjs/typeorm';
import configuration from './config/configuration';
import { RedisModule } from './common/redis/redis.module';
import { I18nModule } from './common/i18n/i18n.module';
import { CacheModule } from './common/cache/cache.module';
import { LocationsModule } from './modules/locations/locations.module';
/**
* وحدة الـworker — عملية منفصلة (`node dist/worker.js`) لا تخدم HTTP.
* تحمل ما يحتاجه العمل الدوري فقط: قاعدة + Redis + المواقع.
*
* جذر تجميع ثانٍ مستقل عن AppModule: الوحدات `@Global` تُسجَّل فقط إن
* استوردها أحدٌ في الشجرة، فما يسجّله AppModule لا يصل إلى هنا مجّاناً.
* المواقع تجرّ الجيوفنس ← الإشعارات ← i18n + cache (وعبر المستخدمين أيضاً).
*/
@Module({
imports: [
ConfigModule.forRoot({ isGlobal: true, load: [configuration] }),
TypeOrmModule.forRootAsync({
inject: [ConfigService],
useFactory: (cfg: ConfigService) => ({
type: 'postgres' as const,
host: cfg.get<string>('db.host'),
port: cfg.get<number>('db.port'),
database: cfg.get<string>('db.name'),
username: cfg.get<string>('db.user'),
password: cfg.get<string>('db.password'),
// بركة أصغر من الـAPI: الـworker يكتب دفعات قليلة لا طلبات متزامنة.
extra: { max: parseInt(process.env.WORKER_DB_POOL_MAX ?? '5', 10) },
entityPrefix: cfg.get<string>('db.tablePrefix'),
synchronize: false,
autoLoadEntities: true,
}),
}),
RedisModule,
I18nModule, // عالمي — نصوص إشعارات الجيوفنس
CacheModule, // عالمي — يحقنه UsersService خلف الإشعارات
LocationsModule,
],
})
export class WorkerModule {}