mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
refactor: server emit events (#11780)
This commit is contained in:
parent
32c05ea950
commit
433c7ab01d
27 changed files with 222 additions and 182 deletions
|
|
@ -6,6 +6,7 @@ import path, { basename, parse } from 'node:path';
|
|||
import picomatch from 'picomatch';
|
||||
import { StorageCore } from 'src/cores/storage.core';
|
||||
import { SystemConfigCore } from 'src/cores/system-config.core';
|
||||
import { OnEmit } from 'src/decorators';
|
||||
import {
|
||||
CreateLibraryDto,
|
||||
LibraryResponseDto,
|
||||
|
|
@ -22,7 +23,7 @@ import { AssetType } from 'src/enum';
|
|||
import { IAssetRepository, WithProperty } from 'src/interfaces/asset.interface';
|
||||
import { ICryptoRepository } from 'src/interfaces/crypto.interface';
|
||||
import { DatabaseLock, IDatabaseRepository } from 'src/interfaces/database.interface';
|
||||
import { OnEvents, SystemConfigUpdateEvent } from 'src/interfaces/event.interface';
|
||||
import { ArgOf } from 'src/interfaces/event.interface';
|
||||
import {
|
||||
IBaseJob,
|
||||
IEntityJob,
|
||||
|
|
@ -45,7 +46,7 @@ import { validateCronExpression } from 'src/validation';
|
|||
const LIBRARY_SCAN_BATCH_SIZE = 5000;
|
||||
|
||||
@Injectable()
|
||||
export class LibraryService implements OnEvents {
|
||||
export class LibraryService {
|
||||
private configCore: SystemConfigCore;
|
||||
private watchLibraries = false;
|
||||
private watchLock = false;
|
||||
|
|
@ -65,7 +66,8 @@ export class LibraryService implements OnEvents {
|
|||
this.configCore = SystemConfigCore.create(systemMetadataRepository, this.logger);
|
||||
}
|
||||
|
||||
async onBootstrapEvent() {
|
||||
@OnEmit({ event: 'onBootstrap' })
|
||||
async onBootstrap() {
|
||||
const config = await this.configCore.getConfig({ withCache: false });
|
||||
|
||||
const { watch, scan } = config.library;
|
||||
|
|
@ -102,7 +104,7 @@ export class LibraryService implements OnEvents {
|
|||
});
|
||||
}
|
||||
|
||||
onConfigValidateEvent({ newConfig }: SystemConfigUpdateEvent) {
|
||||
onConfigValidate({ newConfig }: ArgOf<'onConfigValidate'>) {
|
||||
const { scan } = newConfig.library;
|
||||
if (!validateCronExpression(scan.cronExpression)) {
|
||||
throw new Error(`Invalid cron expression ${scan.cronExpression}`);
|
||||
|
|
@ -187,7 +189,8 @@ export class LibraryService implements OnEvents {
|
|||
}
|
||||
}
|
||||
|
||||
async onShutdownEvent() {
|
||||
@OnEmit({ event: 'onShutdown' })
|
||||
async onShutdown() {
|
||||
await this.unwatchAll();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue