جذر العلّة وراء أعطال الـDI الأربعة: WorkerModule استورد LocationsModule كاملة، فجرّت الجيوفنس ← الإشعارات ← المستخدمين ← المستأجرين، وأربعة متحكّمات HTTP تُنشأ في عملية لا تخدم HTTP. المفرّغ يحقن Redis ومستودعَين لا غير. بإعلانه مباشرةً تسقط الحاجة إلى I18n و Cache و Entitlements التي أضفتها في الدورتين السابقتين. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
44 lines
2.1 KiB
TypeScript
44 lines
2.1 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 { Driver } from './modules/drivers/entities/driver.entity';
|
|
import { DriverTrack } from './modules/locations/entities/driver-track.entity';
|
|
import { LocationFlusherService } from './modules/locations/location-flusher.service';
|
|
|
|
/**
|
|
* وحدة الـworker — عملية منفصلة (`node dist/worker.js`) لا تخدم HTTP.
|
|
*
|
|
* تُعلن المفرّغ مباشرةً بدل استيراد `LocationsModule`: المفرّغ يحقن Redis
|
|
* ومستودعَين لا غير، بينما الوحدة تجرّ خلفها الجيوفنس ← الإشعارات ←
|
|
* المستخدمين ← المستأجرين، وأربعة متحكّمات HTTP في عملية بلا HTTP.
|
|
* جذر التجميع هنا مستقلّ عن AppModule، فالوحدات `@Global` لا تصل مجّاناً —
|
|
* وأضيق شجرة هي أقلّها مفاجآت عند الإقلاع.
|
|
*/
|
|
@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,
|
|
TypeOrmModule.forFeature([Driver, DriverTrack]),
|
|
],
|
|
providers: [LocationFlusherService],
|
|
})
|
|
export class WorkerModule {}
|