Skip to content

Add Requeuer hook preferred by the retry path - #6

Merged
nyergler merged 4 commits into
masterfrom
requeuer-hook
Jul 1, 2026
Merged

nyergler merged 4 commits into
masterfrom
requeuer-hook

Conversation

@nyergler

@nyergler nyergler commented Jul 1, 2026

Copy link
Copy Markdown
Member

Add an optional Requeuer interface a Queue may implement to express the
retry move ("this failed, put it back") distinctly from Enqueue ("add a
new job"). The worker retry path now prefers Requeue with the computed
backoff when the queue implements it, and falls back to Enqueue
otherwise. RedisQueue does not implement Requeuer, so its behavior is
unchanged.

This lets a queue whose waiting and in-flight jobs live in separate
structures restore a failed in-flight job to its position instead of
enqueuing a duplicate.

nyergler added 4 commits June 30, 2026 18:04
Add an optional Requeuer interface a Queue may implement to express the
retry move ("this failed, put it back") distinctly from Enqueue ("add a
new job"). The worker retry path now prefers Requeue with the computed
backoff when the queue implements it, and falls back to Enqueue
otherwise. RedisQueue does not implement Requeuer, so its behavior is
unchanged.

This lets a queue whose waiting and in-flight jobs live in separate
structures restore a failed in-flight job to its position instead of
enqueuing a duplicate.
EnqueuedAt is the Enqueue path's backoff channel (RedisQueue reads it as
the score). The Requeuer path receives the backoff explicitly, so leave
EnqueuedAt untouched there rather than bumping the persisted job's
enqueue time on every retry for no reason a Requeuer should reason about.
A handler error reaching retry is a *wrappedHandlerError, which
Worker.start deliberately suppresses. Returning it after a failed
Requeue hid infrastructure errors that can strand an in-flight job until
its lease lapses. On a Requeue failure, return a distinct error (not a
wrappedHandlerError) that wraps the Requeue error, so the worker's
ErrorFunc reports it. The Enqueue path is unchanged.
Set EnqueuedAt = now.Add(d) unconditionally, reverting the earlier
Enqueue-only scoping. EnqueuedAt is documented as the job's next
execution time and is persisted by a Requeuer and read by status
reporting, so leaving it stale made the stored job disagree with its
actual retry delay. The backoff d is still passed to Requeue explicitly
as the scheduling instruction; the field and the instruction now agree.
@nyergler
nyergler merged commit 64f6228 into master Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant