Skip to content

feat(job): add set(jid:) and jids: to fix job ids, and keep batches from counting a repeated job - #15

Merged
route merged 1 commit into
mainfrom
feat/fixed-jids
Nov 14, 2026
Merged

route merged 1 commit into
mainfrom
feat/fixed-jids

Conversation

@route

@route route commented Nov 14, 2026

Copy link
Copy Markdown
Member

What

  • set(jid:) fixes one job's id, and set(jids:) or perform_bulk(jids:) fixes a bulk's ids (a list, or a callable given each job's arguments), instead of generating them.
  • A fixed jid is sent as the Nats-Msg-Id, so enqueueing the same job again within the stream's duplicate_window is a no-op: JetStream acknowledges it as a duplicate and stores nothing.
  • Inside a batch, the enqueuer now gives back the slot of a job whose publish was acknowledged as a duplicate, for single jobs and bulk. Without it the batch would count the repeat and wait on a job that never runs.

Notes

  • A jid must be 1-128 letters, digits, - or _, because it is the message id and a delayed job's subject token.
  • jid: is for one job and jids: for a bulk; mixing them, or giving a number of jids that is not one per job, raises ArgumentError.
  • Not covered: a repeat after duplicate_window is a real second job, and a hard kill between registering a job in a batch and its ack still leaves the batch's pending count too high.

Tests

Specs for the jid option, the setter guards, bulk jids, and a batch counting a repeated single job and a repeated bulk once.

…rom counting a repeated job

A fixed jid is sent as the Nats-Msg-Id, so JetStream drops a repeat within the stream's duplicate_window. The enqueuer now gives a batch back the slot of a job whose publish was acknowledged as a duplicate, for single jobs and bulk, so the batch neither hangs on nor counts it twice.
@route
route merged commit dad88d9 into main Nov 14, 2026
5 checks passed
@route
route deleted the feat/fixed-jids branch November 14, 2026 17:15
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