From cc0bb9c57451c53c4e6c28ec61afe8ed97f06b95 Mon Sep 17 00:00:00 2001 From: Zack Pollard Date: Mon, 11 Nov 2024 12:50:09 +0000 Subject: [PATCH] fix: config updates not applying for job and storage template service (#14074) --- server/src/services/job.service.spec.ts | 4 ++-- server/src/services/job.service.ts | 8 ++++++-- server/src/services/storage-template.service.spec.ts | 6 +++--- server/src/services/storage-template.service.ts | 8 ++++++-- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/server/src/services/job.service.spec.ts b/server/src/services/job.service.spec.ts index 260497fcea3f6..a23b05073c215 100644 --- a/server/src/services/job.service.spec.ts +++ b/server/src/services/job.service.spec.ts @@ -1,5 +1,5 @@ import { BadRequestException } from '@nestjs/common'; -import { defaults } from 'src/config'; +import { defaults, SystemConfig } from 'src/config'; import { ImmichWorker } from 'src/enum'; import { IAssetRepository } from 'src/interfaces/asset.interface'; import { IConfigRepository } from 'src/interfaces/config.interface'; @@ -31,7 +31,7 @@ describe(JobService.name, () => { describe('onConfigUpdate', () => { it('should update concurrency', () => { - sut.onConfigInitOrUpdate({ newConfig: defaults }); + sut.onConfigUpdate({ newConfig: defaults, oldConfig: {} as SystemConfig }); expect(jobMock.setConcurrency).toHaveBeenCalledTimes(15); expect(jobMock.setConcurrency).toHaveBeenNthCalledWith(5, QueueName.FACIAL_RECOGNITION, 1); diff --git a/server/src/services/job.service.ts b/server/src/services/job.service.ts index 64490d4505264..0528a4a925421 100644 --- a/server/src/services/job.service.ts +++ b/server/src/services/job.service.ts @@ -39,8 +39,7 @@ const asJobItem = (dto: JobCreateDto): JobItem => { @Injectable() export class JobService extends BaseService { @OnEvent({ name: 'config.init' }) - @OnEvent({ name: 'config.update', server: true }) - onConfigInitOrUpdate({ newConfig: config }: ArgOf<'config.init'>) { + onConfigInit({ newConfig: config }: ArgOf<'config.init'>) { if (this.worker !== ImmichWorker.MICROSERVICES) { return; } @@ -56,6 +55,11 @@ export class JobService extends BaseService { } } + @OnEvent({ name: 'config.update', server: true }) + onConfigUpdate({ newConfig: config }: ArgOf<'config.update'>) { + this.onConfigInit({ newConfig: config }); + } + async create(dto: JobCreateDto): Promise { await this.jobRepository.queue(asJobItem(dto)); } diff --git a/server/src/services/storage-template.service.spec.ts b/server/src/services/storage-template.service.spec.ts index 496468a0288b3..728e891d05379 100644 --- a/server/src/services/storage-template.service.spec.ts +++ b/server/src/services/storage-template.service.spec.ts @@ -38,7 +38,7 @@ describe(StorageTemplateService.name, () => { systemMock.get.mockResolvedValue({ storageTemplate: { enabled: true } }); - sut.onConfigInitOrUpdate({ newConfig: defaults }); + sut.onConfigInit({ newConfig: defaults }); }); describe('onConfigValidate', () => { @@ -171,7 +171,7 @@ describe(StorageTemplateService.name, () => { const config = structuredClone(defaults); config.storageTemplate.template = '{{y}}/{{#if album}}{{album}}{{else}}other/{{MM}}{{/if}}/{{filename}}'; - sut.onConfigInitOrUpdate({ newConfig: config }); + sut.onConfigInit({ newConfig: config }); userMock.get.mockResolvedValue(user); assetMock.getByIds.mockResolvedValueOnce([asset]); @@ -192,7 +192,7 @@ describe(StorageTemplateService.name, () => { const user = userStub.user1; const config = structuredClone(defaults); config.storageTemplate.template = '{{y}}/{{#if album}}{{album}}{{else}}other//{{MM}}{{/if}}/{{filename}}'; - sut.onConfigInitOrUpdate({ newConfig: config }); + sut.onConfigInit({ newConfig: config }); userMock.get.mockResolvedValue(user); assetMock.getByIds.mockResolvedValueOnce([asset]); diff --git a/server/src/services/storage-template.service.ts b/server/src/services/storage-template.service.ts index 08566446e369b..e8e4bd12a5569 100644 --- a/server/src/services/storage-template.service.ts +++ b/server/src/services/storage-template.service.ts @@ -75,8 +75,7 @@ export class StorageTemplateService extends BaseService { } @OnEvent({ name: 'config.init' }) - @OnEvent({ name: 'config.update', server: true }) - onConfigInitOrUpdate({ newConfig }: ArgOf<'config.init'>) { + onConfigInit({ newConfig }: ArgOf<'config.init'>) { const template = newConfig.storageTemplate.template; if (!this._template || template !== this.template.raw) { this.logger.debug(`Compiling new storage template: ${template}`); @@ -84,6 +83,11 @@ export class StorageTemplateService extends BaseService { } } + @OnEvent({ name: 'config.update', server: true }) + onConfigUpdate({ newConfig }: ArgOf<'config.update'>) { + this.onConfigInit({ newConfig }); + } + @OnEvent({ name: 'config.validate' }) onConfigValidate({ newConfig }: ArgOf<'config.validate'>) { try {