You've already forked immich
mirror of
https://github.com/immich-app/immich.git
synced 2025-07-08 06:23:00 +02:00
refactor(server): event emits (#10648)
* refactor(server): event emits * refactor: change default priority to 0
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
import { BullModule } from '@nestjs/bullmq';
|
||||
import { Module, OnModuleInit, ValidationPipe } from '@nestjs/common';
|
||||
import { Inject, Module, OnModuleDestroy, OnModuleInit, ValidationPipe } from '@nestjs/common';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import { APP_FILTER, APP_GUARD, APP_INTERCEPTOR, APP_PIPE } from '@nestjs/core';
|
||||
import { APP_FILTER, APP_GUARD, APP_INTERCEPTOR, APP_PIPE, ModuleRef } from '@nestjs/core';
|
||||
import { EventEmitterModule } from '@nestjs/event-emitter';
|
||||
import { ScheduleModule, SchedulerRegistry } from '@nestjs/schedule';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
@ -12,6 +12,7 @@ import { bullConfig, bullQueues, clsConfig, immichAppConfig } from 'src/config';
|
||||
import { controllers } from 'src/controllers';
|
||||
import { databaseConfig } from 'src/database.config';
|
||||
import { entities } from 'src/entities';
|
||||
import { IEventRepository } from 'src/interfaces/event.interface';
|
||||
import { AuthGuard } from 'src/middleware/auth.guard';
|
||||
import { ErrorInterceptor } from 'src/middleware/error.interceptor';
|
||||
import { FileUploadInterceptor } from 'src/middleware/file-upload.interceptor';
|
||||
@ -19,8 +20,7 @@ import { HttpExceptionFilter } from 'src/middleware/http-exception.filter';
|
||||
import { LoggingInterceptor } from 'src/middleware/logging.interceptor';
|
||||
import { repositories } from 'src/repositories';
|
||||
import { services } from 'src/services';
|
||||
import { ApiService } from 'src/services/api.service';
|
||||
import { MicroservicesService } from 'src/services/microservices.service';
|
||||
import { setupEventHandlers } from 'src/utils/events';
|
||||
import { otelConfig } from 'src/utils/instrumentation';
|
||||
|
||||
const common = [...services, ...repositories];
|
||||
@ -50,11 +50,19 @@ const imports = [
|
||||
controllers: [...controllers],
|
||||
providers: [...common, ...middleware],
|
||||
})
|
||||
export class ApiModule implements OnModuleInit {
|
||||
constructor(private service: ApiService) {}
|
||||
export class ApiModule implements OnModuleInit, OnModuleDestroy {
|
||||
constructor(
|
||||
private moduleRef: ModuleRef,
|
||||
@Inject(IEventRepository) private eventRepository: IEventRepository,
|
||||
) {}
|
||||
|
||||
async onModuleInit() {
|
||||
await this.service.init();
|
||||
setupEventHandlers(this.moduleRef);
|
||||
await this.eventRepository.emit('onBootstrapEvent', 'api');
|
||||
}
|
||||
|
||||
async onModuleDestroy() {
|
||||
await this.eventRepository.emit('onShutdownEvent');
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,11 +70,19 @@ export class ApiModule implements OnModuleInit {
|
||||
imports: [...imports],
|
||||
providers: [...common, SchedulerRegistry],
|
||||
})
|
||||
export class MicroservicesModule implements OnModuleInit {
|
||||
constructor(private service: MicroservicesService) {}
|
||||
export class MicroservicesModule implements OnModuleInit, OnModuleDestroy {
|
||||
constructor(
|
||||
private moduleRef: ModuleRef,
|
||||
@Inject(IEventRepository) private eventRepository: IEventRepository,
|
||||
) {}
|
||||
|
||||
async onModuleInit() {
|
||||
await this.service.init();
|
||||
setupEventHandlers(this.moduleRef);
|
||||
await this.eventRepository.emit('onBootstrapEvent', 'microservices');
|
||||
}
|
||||
|
||||
async onModuleDestroy() {
|
||||
await this.eventRepository.emit('onShutdownEvent');
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user