Skip to content

fix(prefix): propagate key prefix to Worker, QueueEvents, and FlowProducer - #25

Merged
msalvatti merged 1 commit into
mainfrom
fix/propagate-prefix
Jul 9, 2026
Merged

fix(prefix): propagate key prefix to Worker, QueueEvents, and FlowProducer#25
msalvatti merged 1 commit into
mainfrom
fix/propagate-prefix

Conversation

@msalvatti

Copy link
Copy Markdown
Member

Problem

Only the producer Queue (QueueService) received options.prefix. The Worker (WorkerRegistry.buildBullOptions), QueueEvents (QueueEventsRegistry), and FlowProducer (FlowService) were constructed without it and fell back to BullMQ's default bull prefix.

With any non-default QUEUE_PREFIX, producers and consumers diverge onto separate Redis keyspaces: workers never consume jobs, @OnQueueEvent listeners never fire, and flow jobs are enqueued where no worker polls. The existing E2E missed this because it runs with the default prefix.

Surfaced while verifying nest-queue-example (which sets QUEUE_PREFIX=nqex): the app booted but the smoke job sat unconsumed in nqex:audit:wait while the worker blocked on bzpopmin against bull:audit:marker.

Fix

Pass the resolved prefix into all three:

  • WorkerRegistry.buildBullOptionsprefix: this.options.prefix.
  • QueueEventsRegistry now injects BYMAX_QUEUE_RESOLVED_OPTIONS and passes prefix to new QueueEvents.
  • FlowService takes a new prefix constructor arg (wired from both module factories) and passes it to new FlowProducer.

Verification

  • build / typecheck / lint OK; unit suite 261 tests, 100% coverage.
  • Added regression tests asserting each object is constructed with the configured prefix.
  • End-to-end against nest-queue-example with QUEUE_PREFIX=nqex: the smoke job now enqueues and completes (audit trail populated within ~1s).

…ts, and FlowProducer

Only the producer Queue received options.prefix; the Worker (WorkerRegistry),
QueueEvents (QueueEventsRegistry), and FlowProducer (FlowService) were created
without it and fell back to BullMQ's default "bull" prefix. With any non-default
QUEUE_PREFIX, producers and consumers diverged onto separate keyspaces, so
workers never consumed jobs, event listeners never fired, and flow jobs were
enqueued where no worker polled.

Pass the resolved prefix into all three: WorkerRegistry.buildBullOptions,
QueueEventsRegistry (now injects BYMAX_QUEUE_RESOLVED_OPTIONS), and FlowService
(new prefix constructor arg, wired from both module factories). Add regression
tests asserting each object is constructed with the configured prefix.
Copilot AI review requested due to automatic review settings July 9, 2026 21:42

Copilot AI left a comment

Copy link
Copy Markdown

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 keyspace mismatch in @bymax-one/nest-queue when a non-default BullMQ prefix is configured, ensuring producers and consumers operate on the same Redis key prefix so jobs, events, and flows are processed correctly.

Changes:

  • Propagates the resolved prefix into BullMQ Worker construction via WorkerRegistry.buildBullOptions.
  • Injects resolved options into QueueEventsRegistry and passes prefix into QueueEvents creation.
  • Extends FlowService to accept a prefix argument and forwards it into FlowProducer, updating module wiring and adding regression tests.

Reviewed changes

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

Show a summary per file
File Description
src/server/services/worker-registry.service.ts Adds prefix to worker options so workers poll the same prefixed keyspace as the producer queue.
src/server/services/worker-registry.service.spec.ts Adds a regression test asserting Worker is constructed with the configured prefix.
src/server/services/queue-events-registry.service.ts Injects resolved options and passes prefix into QueueEvents so event listeners watch the correct keyspace.
src/server/services/queue-events-registry.service.spec.ts Updates setup for new constructor dependency and adds a regression test for QueueEvents prefix.
src/server/services/flow.service.ts Adds prefix argument and passes it to FlowProducer so flow jobs land in the correct keyspace.
src/server/services/flow.service.spec.ts Updates constructor calls and adds a regression test for FlowProducer prefix.
src/server/bymax-queue.module.ts Wires resolved prefix into FlowService for both sync and async module registration paths.

@msalvatti
msalvatti merged commit 617c96c into main Jul 9, 2026
18 checks passed
@msalvatti
msalvatti deleted the fix/propagate-prefix branch July 9, 2026 21:45
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