feat: add JobExhaustedError and reclaim event for orphan tracing
Add a dedicated JobExhaustedError class (src/errors.ts) for claim-time exhaustion: raised when a job is claimed past its maxAttempts without ever completing — typically a worker killed mid-run (deploy/OOM/eviction) that was reclaimed by the stale lease. Carries queue, jobId, attempts, maxAttempts, and lastError (prior attempt's recorded failure, or null if orphaned before any error), so the dead/jobError events are self-explanatory without digging into the database. Exported from the package public API. Add a reclaim event to PrismaQueueEvents, emitted by requeueStale whenever it resets stale claims. Reports the id and stuckForMs of each reclaimed job, connecting the lease recovery to the later dead event on the same id. Rewrite requeueStale() to use a single atomic WITH stale AS (SELECT … FOR UPDATE SKIP LOCKED) UPDATE … SET processedAt = NULL FROM stale RETURNING id, prevProcessedAt statement instead of updateMany — this avoids a snapshot/update race, returns exactly the rows that were reset (not an ambiguous count), and uses SKIP LOCKED to side-step any concurrent dequeue rather than blocking on it.
O
Olivier Louvignes committed
977a92f10459fd150caa83b988b023cc3ee33498
Parent: 00dfe22