fix: restore campaign batch enqueueing

Merged
KM
2mo ago
+33-2

Summary

  • replace the colon in campaign batch custom job IDs with a BullMQ-safe separator
  • add a regression test for the exact queue options passed to BullMQ

Incident and recovery

BullMQ 5.79 rejects custom job IDs containing :, so campaign-batch:<campaignId> prevented every due campaign batch from being enqueued and left campaigns in SCHEDULED or RUNNING.

Existing campaigns are persisted in Postgres and are not lost. After this fix is deployed, the scheduler will discover due SCHEDULED/RUNNING campaigns again and enqueue them with the valid ID. Campaigns that previously completed batches retain lastCursor and CampaignEmail recipient links, so processing resumes without restarting completed recipients. The reported campaign never entered batch processing, so it should start its first batch after rollout.

Verification

  • pnpm --filter web exec vitest run -c vitest.unit.config.ts src/server/service/campaign-service.unit.test.ts -t 'queues batches with a BullMQ-safe custom job ID'
  • pnpm exec prettier --check apps/web/src/server/service/campaign-service.ts apps/web/src/server/service/campaign-service.unit.test.ts

Migration notes

No database migration or data repair is required.

Screenshots

Not applicable; this is a background queue fix.


Summary by cubic

Restores campaign batch enqueueing by switching to a bullmq-safe custom job ID. Previously campaign-batch:<campaignId> was rejected by bullmq v5.79, so due batches were not enqueued and campaigns stayed SCHEDULED/RUNNING; now we use campaign-batch-<campaignId> and the scheduler enqueues due campaigns, resuming from existing cursors without resending completed recipients.

  • Review notes

    • Replace “:” with “-” in the jobId passed to bullmq Queue.add; ID uniqueness semantics are unchanged.
    • Add a unit test that asserts the exact queue options, including the custom jobId.
  • Rollout

    • No migration or data repair required.
    • After deploy, the scheduler will discover due SCHEDULED/RUNNING campaigns and enqueue batches automatically.

Summary by CodeRabbit

  • Bug Fixes

    • Updated campaign batch job identifiers to use a BullMQ-compatible format, improving reliable queue processing.
  • Tests

    • Added coverage to verify campaign batches are queued with the expected payload and job identifier.