Skip to content

Seed keeps system cron rows in sync on every run - #184

Merged
agreenspan merged 3 commits into
mainfrom
fix/cron-seed-sync
Oct 17, 2026
Merged

agreenspan merged 3 commits into
mainfrom
fix/cron-seed-sync

Conversation

@agreenspan

@agreenspan agreenspan commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Update 2026-10-12: the removeRepeatable fix and worker-start prune were split out and merged as #187 (dbe52b9). This PR is rebased on it and now holds only the seed-sync feature (hook skips no-op changes and handles upsert; cron seed syncs name/jobId/handler/description, admin fields insert-only). Full check green on 0c5d938 (one TokensPage UI timeout under load, passes on rerun).

The cron seed was createOnly, so a renamed system job never reached an existing DB (Kingdom prod kept renewConnections after the rename; worker logged "Unknown job handler" every minute). Then the stale repeatable kept firing because the hook never removed anything. Same fixes landed in Kingdom #115 + #116.

Seed

  • cronJob seed syncs name, jobId, handler, description on every seed; pattern, enabled, payload, maxAttempts, backoffMs stay admin-owned (set on insert only via updateOmitFields).
  • cronJobSync hook handles DbAction.upsert (the seed runner already writes inside db.txn since 3f826a1) and skips BullMQ when nothing it reads changed.

Repeatables

  • Hook bug: removeRepeatable(handler, { pattern, jobId }) never matched because BullMQ overwrites repeat.jobId with the third argument. Now removeRepeatable(handler, { pattern }, jobId) (checked against real Redis + BullMQ 5.78).
  • registerCronJobs on worker start removes repeatables no enabled row registered (matched by returned repeatJobKey); prunes nothing if any row failed to register.

Tests: renamed system row updates on re-seed and its repeatable moves; admin-edited fields survive; unchanged re-seed touches nothing; orphan pruning. Full bun run check green.

🤖 Generated with Claude Code

The cron seed was createOnly, so renaming a system job (name, jobId, handler) never reached
an existing database: Kingdom prod kept a renamed handler's old row and the worker failed
"Unknown job handler" every minute.

- cronJob seed: no longer createOnly. Re-seeding syncs name, jobId, handler and description
  from code; pattern, enabled, payload, maxAttempts and backoffMs are admin-editable in
  superadmin and set on insert only (updateOmitFields).
- cronJobSync hook also fires on upsert (the seed runner's write, inside db.txn), and skips
  BullMQ when nothing it reads changed, so a rename moves the repeatable and an unchanged
  re-seed touches nothing.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
agreenspan and others added 2 commits October 17, 2026 17:55
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Main's post-biome lint forbids hand cleanup in test after hooks; cleanupTouchedTables
truncates every table the test wrote.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@agreenspan
agreenspan merged commit 90b6ca0 into main Oct 17, 2026
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.

2 participants