Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: config updates not applying for job and storage template service #14074

Merged
merged 1 commit into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions server/src/services/job.service.spec.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 6 additions & 2 deletions server/src/services/job.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
zackpollard marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -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<void> {
await this.jobRepository.queue(asJobItem(dto));
}
Expand Down
6 changes: 3 additions & 3 deletions server/src/services/storage-template.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe(StorageTemplateService.name, () => {

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

sut.onConfigInitOrUpdate({ newConfig: defaults });
sut.onConfigInit({ newConfig: defaults });
});

describe('onConfigValidate', () => {
Expand Down Expand Up @@ -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]);
Expand All @@ -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]);
Expand Down
8 changes: 6 additions & 2 deletions server/src/services/storage-template.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,19 @@ 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}`);
this._template = this.compile(template);
}
}

@OnEvent({ name: 'config.update', server: true })
onConfigUpdate({ newConfig }: ArgOf<'config.update'>) {
this.onConfigInit({ newConfig });
}

@OnEvent({ name: 'config.validate' })
onConfigValidate({ newConfig }: ArgOf<'config.validate'>) {
try {
Expand Down
Loading