Skip to content

Commit d1fa98c

Browse files
committed
fix(worker): treat job-class backoff entries as milliseconds
`calculateRetryDelay()` multiplied each entry by 1000, but the entries are already milliseconds everywhere else -- the `{ type, delay }` form documents `delay: 5000` as five seconds, and the docs show `backoff = [1000, 2000, 4000]` for exactly that scale. The multiply turned that documented schedule into waits of roughly 16, 33 and 66 minutes. Route the calculation through `backoffDelay()` so this path and the Redis worker agree on both units and per-attempt indexing.
1 parent afc0982 commit d1fa98c

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

packages/bun-queue/src/workers/queue-worker.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { QueueManagerConfig } from '../types'
44
import process from 'node:process'
55
import { FailedJobManager } from '../failed'
66
import { createLogger } from '../logger'
7+
import { backoffDelay } from '../utils'
78

89
export interface WorkerOptions {
910
name?: string
@@ -307,10 +308,12 @@ export class QueueWorker {
307308

308309
if (this.isJobClass(jobData) && jobData.job.backoff) {
309310
const backoff = jobData.job.backoff
310-
if (Array.isArray(backoff)) {
311-
return (backoff[Math.min(queueJob.attemptsMade, backoff.length - 1)] as number) * 1000
312-
}
313-
return backoff * 1000
311+
// `attemptsMade` has not been incremented for the attempt that just
312+
// failed on this path, so shift it to the 1-based count backoffDelay
313+
// expects. Entries are milliseconds, matching the `{ type, delay }`
314+
// form — they used to be multiplied by 1000 here, which turned the
315+
// documented `[1000, 2000, 4000]` into waits of 16 to 66 minutes.
316+
return backoffDelay(Array.isArray(backoff) ? backoff : [backoff], queueJob.attemptsMade + 1)
314317
}
315318

316319
// Default exponential backoff

0 commit comments

Comments
 (0)