mirror of
				https://github.com/immich-app/immich.git
				synced 2025-11-03 19:17:11 -05:00 
			
		
		
		
	fix: config updates not applying for job and storage template service (#14074)
This commit is contained in:
		
							parent
							
								
									f1c9b763cf
								
							
						
					
					
						commit
						d4ca7d0075
					
				@ -1,5 +1,5 @@
 | 
				
			|||||||
import { BadRequestException } from '@nestjs/common';
 | 
					import { BadRequestException } from '@nestjs/common';
 | 
				
			||||||
import { defaults } from 'src/config';
 | 
					import { defaults, SystemConfig } from 'src/config';
 | 
				
			||||||
import { ImmichWorker } from 'src/enum';
 | 
					import { ImmichWorker } from 'src/enum';
 | 
				
			||||||
import { IAssetRepository } from 'src/interfaces/asset.interface';
 | 
					import { IAssetRepository } from 'src/interfaces/asset.interface';
 | 
				
			||||||
import { IConfigRepository } from 'src/interfaces/config.interface';
 | 
					import { IConfigRepository } from 'src/interfaces/config.interface';
 | 
				
			||||||
@ -31,7 +31,7 @@ describe(JobService.name, () => {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  describe('onConfigUpdate', () => {
 | 
					  describe('onConfigUpdate', () => {
 | 
				
			||||||
    it('should update concurrency', () => {
 | 
					    it('should update concurrency', () => {
 | 
				
			||||||
      sut.onConfigInitOrUpdate({ newConfig: defaults });
 | 
					      sut.onConfigUpdate({ newConfig: defaults, oldConfig: {} as SystemConfig });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      expect(jobMock.setConcurrency).toHaveBeenCalledTimes(15);
 | 
					      expect(jobMock.setConcurrency).toHaveBeenCalledTimes(15);
 | 
				
			||||||
      expect(jobMock.setConcurrency).toHaveBeenNthCalledWith(5, QueueName.FACIAL_RECOGNITION, 1);
 | 
					      expect(jobMock.setConcurrency).toHaveBeenNthCalledWith(5, QueueName.FACIAL_RECOGNITION, 1);
 | 
				
			||||||
 | 
				
			|||||||
@ -39,8 +39,7 @@ const asJobItem = (dto: JobCreateDto): JobItem => {
 | 
				
			|||||||
@Injectable()
 | 
					@Injectable()
 | 
				
			||||||
export class JobService extends BaseService {
 | 
					export class JobService extends BaseService {
 | 
				
			||||||
  @OnEvent({ name: 'config.init' })
 | 
					  @OnEvent({ name: 'config.init' })
 | 
				
			||||||
  @OnEvent({ name: 'config.update', server: true })
 | 
					  onConfigInit({ newConfig: config }: ArgOf<'config.init'>) {
 | 
				
			||||||
  onConfigInitOrUpdate({ newConfig: config }: ArgOf<'config.init'>) {
 | 
					 | 
				
			||||||
    if (this.worker !== ImmichWorker.MICROSERVICES) {
 | 
					    if (this.worker !== ImmichWorker.MICROSERVICES) {
 | 
				
			||||||
      return;
 | 
					      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<void> {
 | 
					  async create(dto: JobCreateDto): Promise<void> {
 | 
				
			||||||
    await this.jobRepository.queue(asJobItem(dto));
 | 
					    await this.jobRepository.queue(asJobItem(dto));
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
				
			|||||||
@ -38,7 +38,7 @@ describe(StorageTemplateService.name, () => {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    systemMock.get.mockResolvedValue({ storageTemplate: { enabled: true } });
 | 
					    systemMock.get.mockResolvedValue({ storageTemplate: { enabled: true } });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    sut.onConfigInitOrUpdate({ newConfig: defaults });
 | 
					    sut.onConfigInit({ newConfig: defaults });
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  describe('onConfigValidate', () => {
 | 
					  describe('onConfigValidate', () => {
 | 
				
			||||||
@ -171,7 +171,7 @@ describe(StorageTemplateService.name, () => {
 | 
				
			|||||||
      const config = structuredClone(defaults);
 | 
					      const config = structuredClone(defaults);
 | 
				
			||||||
      config.storageTemplate.template = '{{y}}/{{#if album}}{{album}}{{else}}other/{{MM}}{{/if}}/{{filename}}';
 | 
					      config.storageTemplate.template = '{{y}}/{{#if album}}{{album}}{{else}}other/{{MM}}{{/if}}/{{filename}}';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      sut.onConfigInitOrUpdate({ newConfig: config });
 | 
					      sut.onConfigInit({ newConfig: config });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      userMock.get.mockResolvedValue(user);
 | 
					      userMock.get.mockResolvedValue(user);
 | 
				
			||||||
      assetMock.getByIds.mockResolvedValueOnce([asset]);
 | 
					      assetMock.getByIds.mockResolvedValueOnce([asset]);
 | 
				
			||||||
@ -192,7 +192,7 @@ describe(StorageTemplateService.name, () => {
 | 
				
			|||||||
      const user = userStub.user1;
 | 
					      const user = userStub.user1;
 | 
				
			||||||
      const config = structuredClone(defaults);
 | 
					      const config = structuredClone(defaults);
 | 
				
			||||||
      config.storageTemplate.template = '{{y}}/{{#if album}}{{album}}{{else}}other//{{MM}}{{/if}}/{{filename}}';
 | 
					      config.storageTemplate.template = '{{y}}/{{#if album}}{{album}}{{else}}other//{{MM}}{{/if}}/{{filename}}';
 | 
				
			||||||
      sut.onConfigInitOrUpdate({ newConfig: config });
 | 
					      sut.onConfigInit({ newConfig: config });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      userMock.get.mockResolvedValue(user);
 | 
					      userMock.get.mockResolvedValue(user);
 | 
				
			||||||
      assetMock.getByIds.mockResolvedValueOnce([asset]);
 | 
					      assetMock.getByIds.mockResolvedValueOnce([asset]);
 | 
				
			||||||
 | 
				
			|||||||
@ -75,8 +75,7 @@ export class StorageTemplateService extends BaseService {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  @OnEvent({ name: 'config.init' })
 | 
					  @OnEvent({ name: 'config.init' })
 | 
				
			||||||
  @OnEvent({ name: 'config.update', server: true })
 | 
					  onConfigInit({ newConfig }: ArgOf<'config.init'>) {
 | 
				
			||||||
  onConfigInitOrUpdate({ newConfig }: ArgOf<'config.init'>) {
 | 
					 | 
				
			||||||
    const template = newConfig.storageTemplate.template;
 | 
					    const template = newConfig.storageTemplate.template;
 | 
				
			||||||
    if (!this._template || template !== this.template.raw) {
 | 
					    if (!this._template || template !== this.template.raw) {
 | 
				
			||||||
      this.logger.debug(`Compiling new storage template: ${template}`);
 | 
					      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' })
 | 
					  @OnEvent({ name: 'config.validate' })
 | 
				
			||||||
  onConfigValidate({ newConfig }: ArgOf<'config.validate'>) {
 | 
					  onConfigValidate({ newConfig }: ArgOf<'config.validate'>) {
 | 
				
			||||||
    try {
 | 
					    try {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user