From 9adbbd42beb71047362a72ab536bb8de2f40a547 Mon Sep 17 00:00:00 2001 From: Jason Rasmussen Date: Tue, 28 Mar 2023 14:25:22 -0400 Subject: [PATCH] feat(server): resume queues (#2104) * feat(server): resume queues * chore: regenerate open-api --- mobile/openapi/lib/model/job_command.dart | Bin 2661 -> 2772 bytes server/immich-openapi-specs.json | 1 + server/libs/domain/src/job/job.constants.ts | 1 + server/libs/domain/src/job/job.repository.ts | 1 + .../libs/domain/src/job/job.service.spec.ts | 6 ++++++ server/libs/domain/src/job/job.service.ts | 3 +++ .../libs/domain/test/job.repository.mock.ts | 1 + server/libs/infra/src/job/job.repository.ts | 4 ++++ web/src/api/open-api/api.ts | 1 + 9 files changed, 18 insertions(+) diff --git a/mobile/openapi/lib/model/job_command.dart b/mobile/openapi/lib/model/job_command.dart index 4ebdec26b4f1f08fbded0446c99e6c52e2c53202..6da91e2326d6a4433f0206f7c13854f03f2d7b89 100644 GIT binary patch delta 76 zcmaDVaz%7Q4-;!qYH?}q; pause(name: QueueName): Promise; + resume(name: QueueName): Promise; empty(name: QueueName): Promise; isActive(name: QueueName): Promise; getJobCounts(name: QueueName): Promise; diff --git a/server/libs/domain/src/job/job.service.spec.ts b/server/libs/domain/src/job/job.service.spec.ts index 42ce5e5144..9129b0a183 100644 --- a/server/libs/domain/src/job/job.service.spec.ts +++ b/server/libs/domain/src/job/job.service.spec.ts @@ -93,6 +93,12 @@ describe(JobService.name, () => { expect(jobMock.pause).toHaveBeenCalledWith(QueueName.METADATA_EXTRACTION); }); + it('should handle a resume command', async () => { + await sut.handleCommand(QueueName.METADATA_EXTRACTION, { command: JobCommand.RESUME, force: false }); + + expect(jobMock.resume).toHaveBeenCalledWith(QueueName.METADATA_EXTRACTION); + }); + it('should handle an empty command', async () => { await sut.handleCommand(QueueName.METADATA_EXTRACTION, { command: JobCommand.EMPTY, force: false }); diff --git a/server/libs/domain/src/job/job.service.ts b/server/libs/domain/src/job/job.service.ts index 2ca036280a..ccb1709aae 100644 --- a/server/libs/domain/src/job/job.service.ts +++ b/server/libs/domain/src/job/job.service.ts @@ -21,6 +21,9 @@ export class JobService { case JobCommand.PAUSE: return this.jobRepository.pause(queueName); + case JobCommand.RESUME: + return this.jobRepository.resume(queueName); + case JobCommand.EMPTY: return this.jobRepository.empty(queueName); } diff --git a/server/libs/domain/test/job.repository.mock.ts b/server/libs/domain/test/job.repository.mock.ts index 5b2d9547b2..a6c8fff2a1 100644 --- a/server/libs/domain/test/job.repository.mock.ts +++ b/server/libs/domain/test/job.repository.mock.ts @@ -4,6 +4,7 @@ export const newJobRepositoryMock = (): jest.Mocked => { return { empty: jest.fn(), pause: jest.fn(), + resume: jest.fn(), queue: jest.fn().mockImplementation(() => Promise.resolve()), isActive: jest.fn(), getJobCounts: jest.fn(), diff --git a/server/libs/infra/src/job/job.repository.ts b/server/libs/infra/src/job/job.repository.ts index 1fbacd840a..0371ab50df 100644 --- a/server/libs/infra/src/job/job.repository.ts +++ b/server/libs/infra/src/job/job.repository.ts @@ -45,6 +45,10 @@ export class JobRepository implements IJobRepository { return this.queueMap[name].pause(); } + resume(name: QueueName) { + return this.queueMap[name].resume(); + } + empty(name: QueueName) { return this.queueMap[name].empty(); } diff --git a/web/src/api/open-api/api.ts b/web/src/api/open-api/api.ts index 19546ee548..c139fef28f 100644 --- a/web/src/api/open-api/api.ts +++ b/web/src/api/open-api/api.ts @@ -1222,6 +1222,7 @@ export interface GetAssetCountByTimeBucketDto { export const JobCommand = { Start: 'start', Pause: 'pause', + Resume: 'resume', Empty: 'empty' } as const;