refactor(server): event emits (#10648)

* refactor(server): event emits

* refactor: change default priority to 0
This commit is contained in:
Jason Rasmussen
2024-06-27 15:54:20 -04:00
committed by GitHub
parent 7e99394c70
commit 72bf9439b0
25 changed files with 222 additions and 171 deletions

View File

@@ -2,6 +2,7 @@ import { Inject, Injectable } from '@nestjs/common';
import { SystemConfigCore } from 'src/cores/system-config.core';
import { IAssetRepository, WithoutProperty } from 'src/interfaces/asset.interface';
import { DatabaseLock, IDatabaseRepository } from 'src/interfaces/database.interface';
import { OnEvents, SystemConfigUpdate } from 'src/interfaces/event.interface';
import {
IBaseJob,
IEntityJob,
@@ -19,7 +20,7 @@ import { isSmartSearchEnabled } from 'src/utils/misc';
import { usePagination } from 'src/utils/pagination';
@Injectable()
export class SmartInfoService {
export class SmartInfoService implements OnEvents {
private configCore: SystemConfigCore;
constructor(
@@ -49,6 +50,12 @@ export class SmartInfoService {
await this.jobRepository.resume(QueueName.SMART_SEARCH);
}
async onConfigUpdateEvent({ oldConfig, newConfig }: SystemConfigUpdate) {
if (oldConfig.machineLearning.clip.modelName !== newConfig.machineLearning.clip.modelName) {
await this.repository.init(newConfig.machineLearning.clip.modelName);
}
}
async handleQueueEncodeClip({ force }: IBaseJob): Promise<JobStatus> {
const { machineLearning } = await this.configCore.getConfig({ withCache: false });
if (!isSmartSearchEnabled(machineLearning)) {