fix(jobs): Use bullmq's deduplication to simplify album update and migration workers
parent
21d6755f39
commit
dcc720a74f
|
|
@ -219,12 +219,12 @@ export class JobRepository {
|
|||
switch (item.name) {
|
||||
case JobName.NotifyAlbumUpdate: {
|
||||
return {
|
||||
jobId: `${item.data.id}/${item.data.recipientId}`,
|
||||
deduplication: { id: `${item.data.id}/${item.data.recipientId}`, replace: true },
|
||||
delay: item.data?.delay,
|
||||
};
|
||||
}
|
||||
case JobName.StorageTemplateMigrationSingle: {
|
||||
return { jobId: item.data.id };
|
||||
return { deduplication: { id: item.data.id } };
|
||||
}
|
||||
case JobName.PersonGenerateThumbnail: {
|
||||
return { priority: 1 };
|
||||
|
|
@ -247,13 +247,4 @@ export class JobRepository {
|
|||
private getQueue(queue: QueueName): Queue {
|
||||
return this.moduleRef.get<Queue>(getQueueToken(queue), { strict: false });
|
||||
}
|
||||
|
||||
/** @deprecated */
|
||||
// todo: remove this when asset notifications no longer need it.
|
||||
public async removeJob(name: JobName, jobID: string): Promise<void> {
|
||||
const existingJob = await this.getQueue(this.getQueueName(name)).getJob(jobID);
|
||||
if (existingJob) {
|
||||
await existingJob.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -523,7 +523,6 @@ describe(NotificationService.name, () => {
|
|||
|
||||
it('should add new recipients for new images if job is already queued', async () => {
|
||||
await sut.onAlbumUpdate({ id: '1', recipientId: '2' } as INotifyAlbumUpdateJob);
|
||||
expect(mocks.job.removeJob).toHaveBeenCalledWith(JobName.NotifyAlbumUpdate, '1/2');
|
||||
expect(mocks.job.queue).toHaveBeenCalledWith({
|
||||
name: JobName.NotifyAlbumUpdate,
|
||||
data: {
|
||||
|
|
|
|||
|
|
@ -218,7 +218,6 @@ export class NotificationService extends BaseService {
|
|||
|
||||
@OnEvent({ name: 'AlbumUpdate' })
|
||||
async onAlbumUpdate({ id, recipientId }: ArgOf<'AlbumUpdate'>) {
|
||||
await this.jobRepository.removeJob(JobName.NotifyAlbumUpdate, `${id}/${recipientId}`);
|
||||
await this.jobRepository.queue({
|
||||
name: JobName.NotifyAlbumUpdate,
|
||||
data: { id, recipientId, delay: NotificationService.albumUpdateEmailDelayMs },
|
||||
|
|
|
|||
|
|
@ -19,6 +19,5 @@ export const newJobRepositoryMock = (): Mocked<RepositoryInterface<JobRepository
|
|||
getJobCounts: vitest.fn(),
|
||||
clear: vitest.fn(),
|
||||
waitForQueueCompletion: vitest.fn(),
|
||||
removeJob: vitest.fn(),
|
||||
};
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue