Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't define a concurrency with a 0 value using the @Processor decorator #258

Closed
nlenepveu opened this issue Jan 30, 2020 · 1 comment
Closed

Comments

@nlenepveu
Copy link
Contributor

I'm submitting a...


[ ] Regression 
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

Current behavior

In the current design of Bull, the concurrency is managed at the processor level and does not allow to easily configure a single queue with no concurrency used by multiple named processors.
Given the fact that concurrency of each processor stacks up for the queue, a workaround exists and consists of defining a concurrency to 0 to every processor of the queue expected the first one. The workaround is described here: OptimalBits/bull#1113.

Using the NestJS/Bull decorator, the code below should do the trick

@Process({ name: NAMED_JOB_1, concurrency: 1 })
async updateJob1(job: Job<any>) { }

@Process({ name: NAMED_JOB_2, concurrency: 0 })
async updateJob2(job: Job<any>) { }

However, any argument with a falsy value is rejected before calling queue.process with the options of the decorator (https://github.com/nestjs/bull/blob/master/lib/bull.explorer.ts#L82).

  handleProcessor(
    instance: object,
    key: string,
    queue: Queue,
    options?: ProcessOptions,
  ) {
    let args = [
      options && options.name,
      options && options.concurrency,
      instance[key].bind(instance) as ProcessCallbackFunction<unknown>,
    ];
    args = args.filter(item => item);
    queue.process.call(queue, ...args);
  }

Expected behavior

Concurrency options with a 0 value should be a valid option and should not be rejected by the @Processor decorator.

    args = args.filter(item => item);

could be changed to

    args = args.filter(item => item !== undefined);

Environment


Nest version: 6.10.14
Nest bull version: 0.0.1
 
For Tooling issues:
OS Version     : Linux 4.15
NodeJS Version : v12.14.1
NPM Version    : 6.13.4
@kamilmysliwiec
Copy link
Member

Fixed in 0.0.2. Thanks!

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

No branches or pull requests

2 participants