Skip to content

Commit d9e9e28

Browse files
zackpollardyosit
authored andcommitted
fix: config updates not applying for job and storage template service (immich-app#14074)
1 parent 2f48277 commit d9e9e28

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

server/src/services/job.service.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { BadRequestException } from '@nestjs/common';
2-
import { defaults } from 'src/config';
2+
import { defaults, SystemConfig } from 'src/config';
33
import { ImmichWorker } from 'src/enum';
44
import { IAssetRepository } from 'src/interfaces/asset.interface';
55
import { IConfigRepository } from 'src/interfaces/config.interface';
@@ -31,7 +31,7 @@ describe(JobService.name, () => {
3131

3232
describe('onConfigUpdate', () => {
3333
it('should update concurrency', () => {
34-
sut.onConfigInitOrUpdate({ newConfig: defaults });
34+
sut.onConfigUpdate({ newConfig: defaults, oldConfig: {} as SystemConfig });
3535

3636
expect(jobMock.setConcurrency).toHaveBeenCalledTimes(15);
3737
expect(jobMock.setConcurrency).toHaveBeenNthCalledWith(5, QueueName.FACIAL_RECOGNITION, 1);

server/src/services/job.service.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ const asJobItem = (dto: JobCreateDto): JobItem => {
3939
@Injectable()
4040
export class JobService extends BaseService {
4141
@OnEvent({ name: 'config.init' })
42-
@OnEvent({ name: 'config.update', server: true })
43-
onConfigInitOrUpdate({ newConfig: config }: ArgOf<'config.init'>) {
42+
onConfigInit({ newConfig: config }: ArgOf<'config.init'>) {
4443
if (this.worker !== ImmichWorker.MICROSERVICES) {
4544
return;
4645
}
@@ -56,6 +55,11 @@ export class JobService extends BaseService {
5655
}
5756
}
5857

58+
@OnEvent({ name: 'config.update', server: true })
59+
onConfigUpdate({ newConfig: config }: ArgOf<'config.update'>) {
60+
this.onConfigInit({ newConfig: config });
61+
}
62+
5963
async create(dto: JobCreateDto): Promise<void> {
6064
await this.jobRepository.queue(asJobItem(dto));
6165
}

server/src/services/storage-template.service.spec.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ describe(StorageTemplateService.name, () => {
3838

3939
systemMock.get.mockResolvedValue({ storageTemplate: { enabled: true } });
4040

41-
sut.onConfigInitOrUpdate({ newConfig: defaults });
41+
sut.onConfigInit({ newConfig: defaults });
4242
});
4343

4444
describe('onConfigValidate', () => {
@@ -171,7 +171,7 @@ describe(StorageTemplateService.name, () => {
171171
const config = structuredClone(defaults);
172172
config.storageTemplate.template = '{{y}}/{{#if album}}{{album}}{{else}}other/{{MM}}{{/if}}/{{filename}}';
173173

174-
sut.onConfigInitOrUpdate({ newConfig: config });
174+
sut.onConfigInit({ newConfig: config });
175175

176176
userMock.get.mockResolvedValue(user);
177177
assetMock.getByIds.mockResolvedValueOnce([asset]);
@@ -192,7 +192,7 @@ describe(StorageTemplateService.name, () => {
192192
const user = userStub.user1;
193193
const config = structuredClone(defaults);
194194
config.storageTemplate.template = '{{y}}/{{#if album}}{{album}}{{else}}other//{{MM}}{{/if}}/{{filename}}';
195-
sut.onConfigInitOrUpdate({ newConfig: config });
195+
sut.onConfigInit({ newConfig: config });
196196

197197
userMock.get.mockResolvedValue(user);
198198
assetMock.getByIds.mockResolvedValueOnce([asset]);

server/src/services/storage-template.service.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,19 @@ export class StorageTemplateService extends BaseService {
7575
}
7676

7777
@OnEvent({ name: 'config.init' })
78-
@OnEvent({ name: 'config.update', server: true })
79-
onConfigInitOrUpdate({ newConfig }: ArgOf<'config.init'>) {
78+
onConfigInit({ newConfig }: ArgOf<'config.init'>) {
8079
const template = newConfig.storageTemplate.template;
8180
if (!this._template || template !== this.template.raw) {
8281
this.logger.debug(`Compiling new storage template: ${template}`);
8382
this._template = this.compile(template);
8483
}
8584
}
8685

86+
@OnEvent({ name: 'config.update', server: true })
87+
onConfigUpdate({ newConfig }: ArgOf<'config.update'>) {
88+
this.onConfigInit({ newConfig });
89+
}
90+
8791
@OnEvent({ name: 'config.validate' })
8892
onConfigValidate({ newConfig }: ArgOf<'config.validate'>) {
8993
try {

0 commit comments

Comments
 (0)