feat: re-register repeatable jobs on Redis reconnect#37
Merged
Conversation
Repeatable BullMQ jobs (poll ticks for pr-watcher, repo-cleanup, ticket-sync, workflow-trigger-checker, token-validation, reconcile-resync) were registered only at API boot. A Redis restart/flush wipes the repeat schedulers, so the pollers silently stop until the API is restarted. Add a single source of truth (REPEATABLE_JOBS) plus idempotent ensureRepeatJobs(), and a dedicated monitor connection that re-registers them on every reconnect (debounced). Workers no longer self-register inline, so boot and reconnect share the same definitions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Repeatable BullMQ jobs — the poll ticks for
pr-watcher,repo-cleanup(health-check + stall-check),ticket-sync,workflow-trigger-checker,token-validation, andreconcile-resync— were registered only at API boot (inside eachstartXxxWorker()).A Redis restart/flush (e.g. a Redis pod OOMKill) wipes the repeat scheduler keys. Nothing re-adds them, so the pollers silently stop until the API itself is restarted. Notably this halts the schedule-trigger poll loop, so timed Tasks stop firing.
(The user-defined schedules themselves live in Postgres
workflow_triggers.nextFireAtand are unaffected — only the BullMQ tick that reads them is lost.)Change
services/repeatable-jobs.ts—REPEATABLE_JOBS, a single source of truth for every repeat job (sameOPTIO_*env vars + defaults as before), andensureRepeatJobs(): idempotentqueue.add(..., {repeat})per entry, in-flight guard, never throws.services/repeat-job-monitor.ts— a dedicated ioredis connection. The firstready(boot) is ignored; every laterready(reconnect) debounces 2s then callsensureRepeatJobs(). Wired intoindex.tsstartup and graceful shutdown.queue.add(...repeat...)registrations so boot and reconnect share the same definitions (no drift).index.tsnow doescleanRepeatJobs→ensureRepeatJobs()→ start workers → start monitor.Scope note
Recovery triggers on reconnect only (the actual OOMKill/restart failure mode — the TCP socket drops and ioredis re-fires
ready). A logicalFLUSHALL/eviction that leaves the socket up emits noreadyand is intentionally out of scope.Tests
repeatable-jobs.test.ts— registers exactly theREPEATABLE_JOBSentries with correct repeat options, closes each queue, in-flight guard shares one pass across concurrent calls.repeat-job-monitor.test.ts— firstreadyignored, reconnect re-registers after debounce, burst of reconnects debounced into one,stopquits the connection.Verification
pnpm turbo typecheck✓pnpm turbo test✓ (2022 passing, incl. 7 new)prettier --check✓ /eslint0 errors