01 · Before and afterThe pattern
// before: on a stall, try again later from the same cursor, forever
await enqueue({ resumeFrom: cursor }, { delayMs: 120_000 });
// after: count stalls across runs, give up loudly
const stalled = madeNoProgress ? (payload.stalledRunCount ?? 0) + 1 : 0;
if (stalled >= MAX_STALLED_RUNS) throw new Error(`Backfill stuck at ${JSON.stringify(cursor)}`);
await enqueue({ resumeFrom: cursor, stalledRunCount: stalled }, { delayMs: 120_000 });02 · Run it on your appThe check
Do any of your background jobs schedule a follow-up job of themselves? What stops that chain if the same step keeps failing?
If the honest answer is no or not sure, this is worth a look before it reaches production.