Skip to content

Comments

fix: providers.refresh queue is created on scheduler startup#302

Merged
SgtPooki merged 1 commit intomainfrom
fix/create-provider-refresh-queue
Feb 24, 2026
Merged

fix: providers.refresh queue is created on scheduler startup#302
SgtPooki merged 1 commit intomainfrom
fix/create-provider-refresh-queue

Conversation

@SgtPooki
Copy link
Collaborator

Summary

This PR fixes intermittent worker startup errors:

Queue providers.refresh does not exist (Queue: providers.refresh, Worker: ...)

Root Cause

JobsService registered a worker for providers.refresh, but startup only explicitly created sp.work.

In our deployed topology (DEALBOT_RUN_MODE=worker, DEALBOT_PGBOSS_SCHEDULER_ENABLED=false), workers can start polling before the scheduler ever creates providers.refresh, causing repeated pg-boss errors.

Fix

  • Added explicit startup queue creation for all worker-consumed queues:
  1. sp.work (singleton policy)
  2. metrics.run
  3. metrics.cleanup
  4. providers.refresh
  • Refactored queue creation into a dedicated ensureWorkerQueues(...) helper invoked from startBoss().

Tests

  • Updated worker registration test to assert providers.refresh worker registration.
  • Added a new test to verify all required queues are created during startup.
  • Verified with:
    • pnpm -C apps/backend test -- src/jobs/jobs.service.spec.ts

Notes

  • Keeping queue creation in worker startup is intentional: createQueue is idempotent and avoids scheduler/worker startup races.
  • No infra/env changes required.

Copilot AI review requested due to automatic review settings February 24, 2026 15:04
@SgtPooki SgtPooki self-assigned this Feb 24, 2026
@SgtPooki SgtPooki added this to FOC Feb 24, 2026
@SgtPooki SgtPooki moved this to 🔎 Awaiting review in FOC Feb 24, 2026
@SgtPooki SgtPooki added this to the M4.1: mainnet ready milestone Feb 24, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a race condition where workers could start polling for jobs before the scheduler created the providers.refresh queue, causing intermittent startup errors. The fix ensures all worker-consumed queues are created explicitly during worker startup, making queue creation independent of scheduler timing.

Changes:

  • Refactored queue creation into a dedicated ensureWorkerQueues() helper method
  • Added explicit creation for all four worker-consumed queues: sp.work, metrics.run, metrics.cleanup, and providers.refresh
  • Updated tests to verify all worker queues are created and registered properly

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
apps/backend/src/jobs/jobs.service.ts Extracted queue creation logic into ensureWorkerQueues() method and added creation for all worker-consumed queues
apps/backend/src/jobs/jobs.service.spec.ts Added test for new ensureWorkerQueues() method and updated existing test to use queue constants instead of hardcoded strings

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-project-automation github-project-automation bot moved this from 🔎 Awaiting review to ✔️ Approved by reviewer in FOC Feb 24, 2026
@SgtPooki SgtPooki merged commit 29b7a69 into main Feb 24, 2026
11 checks passed
@SgtPooki SgtPooki deleted the fix/create-provider-refresh-queue branch February 24, 2026 15:15
@github-project-automation github-project-automation bot moved this from ✔️ Approved by reviewer to 🎉 Done in FOC Feb 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: 🎉 Done

Development

Successfully merging this pull request may close these issues.

2 participants