api/src/app.module.ts
import { Module, OnModuleInit } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { typeOrmConfig } from 'typeorm.config';
import { AuthenticationModule } from 'modules/authentication/authentication.module';
import { UsersModule } from 'modules/users/users.module';
import { APP_FILTER } from '@nestjs/core';
import { AllExceptionsFilter } from 'filters/all-exceptions.exception.filter';
import { SuppliersModule } from 'modules/suppliers/suppliers.module';
import { BusinessUnitsModule } from 'modules/business-units/business-units.module';
import { MaterialsModule } from 'modules/materials/materials.module';
import { AdminRegionsModule } from 'modules/admin-regions/admin-regions.module';
import { GeoRegionsModule } from 'modules/geo-regions/geo-regions.module';
import { SourcingLocationsModule } from 'modules/sourcing-locations/sourcing-locations.module';
import { SourcingRecordsModule } from 'modules/sourcing-records/sourcing-records.module';
import { IndicatorsModule } from 'modules/indicators/indicators.module';
import { IndicatorCoefficientsModule } from 'modules/indicator-coefficients/indicator-coefficients.module';
import { TerminusModule } from '@nestjs/terminus';
import { HealthController } from 'health.controller';
import { UnitsModule } from 'modules/units/units.module';
import { UnitConversionsModule } from 'modules/unit-conversions/unit-conversions.module';
import { SourcingLocationGroupsModule } from 'modules/sourcing-location-groups/sourcing-location-groups.module';
import { ScenariosModule } from 'modules/scenarios/scenarios.module';
import { ScenarioInterventionsModule } from 'modules/scenario-interventions/scenario-interventions.module';
import { ImportDataModule } from 'modules/import-data/import-data.module';
import { IndicatorRecordsModule } from 'modules/indicator-records/indicator-records.module';
import { GeoCodingModule } from 'modules/geo-coding/geo-coding.module';
import { H3DataModule } from 'modules/h3-data/h3-data.module';
import { HttpModule } from '@nestjs/axios';
import { BullModule } from '@nestjs/bull';
import { ImpactModule } from 'modules/impact/impact.module';
import { TasksModule } from 'modules/tasks/tasks.module';
import { TargetsModule } from 'modules/targets/targets.module';
import { UrlParamsModule } from 'modules/url-params/url-params.module';
import { ContextualLayersModule } from 'modules/contextual-layers/contextual-layers.module';
import { CachedDataModule } from 'modules/cached-data/cached-data.module';
import * as config from 'config';
import { AuthorizationModule } from 'modules/authorization/authorization.module';
import { AuthorizationService } from 'modules/authorization/authorization.service';
import { TasksService } from 'modules/tasks/tasks.service';
import { NotificationsModule } from 'modules/notifications/notifications.module';
import { ReportsModule } from 'modules/reports/reports.module';
import { EudrModule } from 'modules/eudr-alerts/eudr.module';
import { WebSocketsModule } from 'modules/notifications/websockets/websockets.module';
import { AppEventsModule } from 'modules/events/app-events.module';
const queueConfig: any = config.get('queue');
@Module({
imports: [
HttpModule,
TypeOrmModule.forRoot({ ...typeOrmConfig, autoLoadEntities: true }),
BullModule.forRoot({
redis: {
host: queueConfig.host,
port: queueConfig.port,
db: queueConfig.database,
},
settings: { lockDuration: 10000000, maxStalledCount: 0 },
}),
AdminRegionsModule,
AuthenticationModule,
BusinessUnitsModule,
CachedDataModule,
ContextualLayersModule,
GeoCodingModule,
GeoRegionsModule,
H3DataModule,
ImpactModule,
ImportDataModule,
IndicatorCoefficientsModule,
IndicatorRecordsModule,
IndicatorsModule,
MaterialsModule,
ScenarioInterventionsModule,
ScenariosModule,
SourcingLocationGroupsModule,
SourcingLocationsModule,
SourcingRecordsModule,
SuppliersModule,
TargetsModule,
TasksModule,
TerminusModule,
UnitConversionsModule,
UnitsModule,
UrlParamsModule,
UsersModule,
AuthorizationModule,
NotificationsModule,
ReportsModule,
WebSocketsModule,
EudrModule,
AppEventsModule,
],
providers: [
{
provide: APP_FILTER,
useClass: AllExceptionsFilter,
},
],
controllers: [HealthController],
})
export class AppModule implements OnModuleInit {
constructor(
private readonly authorizationService: AuthorizationService,
private readonly taskService: TasksService,
) {}
async onModuleInit(): Promise<void> {
await this.authorizationService.seedRolesAndPermissions();
await this.taskService.cleanStalledTasks();
//TODO: Clean possible stalled async jobs
}
}