From ba55319a84e293137336dfad62b5c580bc3e11b4 Mon Sep 17 00:00:00 2001 From: oharbo Date: Mon, 16 Mar 2026 20:28:54 +0000 Subject: [PATCH] fix: deduplicate jobs from getJobsForWorker to prevent parallel execution of same job --- src/Queue.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Queue.ts b/src/Queue.ts index 5d3ea41..a2c6756 100644 --- a/src/Queue.ts +++ b/src/Queue.ts @@ -233,7 +233,9 @@ export class Queue { const nextJob = await this.jobStore.getNextJob(); if (this.isJobNotEmpty(nextJob)) { const nextJobs = await this.getJobsForWorker(nextJob.workerName); - const processingJobs = nextJobs.map(async (job) => this.limitExecution(this.excuteJob, job)); + // Deduplicate by job id - native getJobsForWorker may return same job multiple times when count > available jobs + const uniqueJobs = nextJobs.filter((job, i, arr) => arr.findIndex((j) => j.id === job.id) === i); + const processingJobs = uniqueJobs.map(async (job) => this.limitExecution(this.excuteJob, job)); await Promise.all(processingJobs); } else if (!this.isExecuting()) { this.finishQueue();