Repository navigation
12.34.0
Schema version: 42, unchanged from 12.33.0
redrive()can be filtered by payload, age and id, andpreviewRedrive()reports what a redrive would do before it does it.redrive()now works on CockroachDB- Some test clock fixes
Filtered redrive, and a preview before it runs
redrive() moves jobs out of a dead letter queue and re-creates them on the queue they came from. Until now the only way to narrow it was by source queue, so draining a dead letter queue was all or nothing per source. It now takes three more filters:
data: only jobs whose payload contains this object, matched the same way asfindJobs()createdBefore: only jobs that arrived in the dead letter queue before thisDateids: only these jobs, by their id in the dead letter queue
createdBefore is also how to drain a fixed set across several calls. Pass one cutoff to every call and jobs dead-lettered while the loop runs are never swept in:
const cutoff = new Date()
let moved
do {
moved = await boss.redrive('payments-dlq', { data: { tenant: 'acme' }, createdBefore: cutoff, limit: 500 })
} while (moved > 0)The new previewRedrive() takes the same options (minus limit) and moves nothing. It returns the total, where the jobs would fan out to, and how many a redrive would leave behind because they have no recorded source queue and no destination was given, or their source queue has since been deleted:
const { total, destinations, unroutable } = await boss.previewRedrive('payments-dlq', {
data: { tenant: 'acme' }
})
// { total: 12431, destinations: [{ name: 'payment-processing', count: 12113 }, { name: 'payment-refunds', count: 310 }], unroutable: 8 }The preview and the redrive read one shared predicate, so the preview cannot count a job the redrive would skip. What it cannot see is a collision at redrive time: a destination with a singleton or short policy can still drop a job whose key is already taken, exactly as redrive() always has.
Only jobs still waiting in the dead letter queue are candidates, as before. A job the dead letter queue's own workers have failed stays where it is.
redrive() on CockroachDB
redrive() failed on CockroachDB on every call, because it deletes from and inserts into the job table in one statement, which CockroachDB refuses. On CockroachDB the same move now runs as three statements in one transaction, with the same filters, order and limit, so it moves the same jobs.
Fixes
- A job in a dead letter queue forgot where it came from the first time that queue's own worker failed it. Failing a job deletes and re-inserts it, and the re-insert did not copy
sourceName,sourceId,sourceCreatedOnorsourceRetryCount. After thatredrive()could not route the job back and left it in place. The re-insert now carries the four fields on PostgreSQL and CockroachDB alike. Jobs that already lost them are not repaired; redrive those with an explicitdestination. - When two redriven jobs collide on a destination's
singletonorshortpolicy, PostgreSQL now keeps the older one. Before, which one survived depended on the physical order of the rows. CockroachDB ignores that ordering when it resolves the conflict, so there either one may be kept. - On CockroachDB,
update()andupdateQueue()failed on every call, because they usedjsonb_exists(), which CockroachDB does not have. - On CockroachDB,
detectSchemaDrift()reported drift on every fresh install, because CockroachDB stores its own rewriting of index definitions and function bodies. On CockroachDB it now reports missing and invalid indexes and functions without comparing their definitions, as it already did for column types, defaults and constraints. - On CockroachDB,
findJobs()returned integer fields as strings, and no read convertedsourceRetryCount.fetch(),getJobById()andfindJobs()now all return numbers. TestClock.setTime()moving forward left in-process deadlines, such as handler expiration, behind the database, and the nexttick()replayed every skipped interval period, about 43,000 callbacks for a one-day jump. Timers that the jump makes overdue now fire once on the next tick, and intervals keep their period from the new time. A backward jump leaves pending timers alone.setTime()called during a tick now throws instead of losing the jump. Thanks for the PR by @bhamiltoncx in #922
Full Changelog: 12.33.7...12.34.0