Skip to content

fix: queue option ignored when group is not set#1

Open
seth-shi wants to merge 1 commit into
codecarrotlabs:mainfrom
seth-shi:fix/queue-option-ignored
Open

fix: queue option ignored when group is not set#1
seth-shi wants to merge 1 commit into
codecarrotlabs:mainfrom
seth-shi:fix/queue-option-ignored

Conversation

@seth-shi

Copy link
Copy Markdown

Bug

When enqueuing a task with a custom queue option but no group, the queue is silently ignored and the task always goes to the default queue.

Reproduction:

const client = new AsynqClient("redis://localhost:6379");
const task = new Task("email:send", { userId: 1 });

// Expected: enqueued to "critical" queue
// Actual: enqueued to "default" queue
await client.enqueue(task, { queue: "critical" });

Root Cause

In composeOptions, the queue assignment was nested inside the if (opts?.group) block:

// before (buggy)
if (opts?.group) {
  const qname = opts.queue || "";
  base.validateQueueName(qname);
  res.queue = qname;  // only runs when group is set!
}

Fix

Move queue handling into its own independent block, separate from group:

// after
if (opts?.queue) {
  base.validateQueueName(opts.queue);
  res.queue = opts.queue;
}

if (opts?.group) {
  if (opts.group.trim().length === 0) {
    throw new Error("group key cannot be empty");
  }
  res.group = opts.group.trim();
}

The `queue` option in `processOptions` was nested inside the `if (opts?.group)` block,
causing it to be silently ignored whenever `group` was not provided. This meant tasks
were always enqueued to the default queue regardless of the `queue` option passed.

Fix: move `queue` handling into its own independent block.
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.

1 participant