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

[Bug]: Setting a concurrency doesn't change the concurrency field on the worker #2880

Closed
1 task done
nlochschmidt opened this issue Nov 4, 2024 · 2 comments
Closed
1 task done
Assignees
Labels
bug Something isn't working

Comments

@nlochschmidt
Copy link

nlochschmidt commented Nov 4, 2024

Version

v5.22.0

Platform

NodeJS

What happened?

When we set a concurrency on a worker in the constructor and then set a new concurrency using the setter worker.concurrency = 10, then worker.concurrency is still the concurrency of the worker set in the constructor is undefined.

We can use worker.opts.concurrency to get the current concurrency but this seems like a bug.

Relevant code:

this.concurrency = this.opts.concurrency;

and

set concurrency(concurrency: number) {
if (
typeof concurrency !== 'number' ||
concurrency < 1 ||
!isFinite(concurrency)
) {
throw new Error('concurrency must be a finite number greater than 0');
}
this.opts.concurrency = concurrency;
}

How to reproduce.

const worker = new Worker('test', async job => {}, { concurrency: 100 });
worker.concurrency = 10
assert(worker.concurrency == 10)

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@nlochschmidt nlochschmidt added the bug Something isn't working label Nov 4, 2024
@nlochschmidt
Copy link
Author

Oh, actually, it seems like the value of worker.concurrency is also not the one from the constructor but actually undefined, but TypeScript doesn't complain about this:

const maxTasks: number = worker.concurrency

@nlochschmidt
Copy link
Author

Related microsoft/TypeScript#11596 (comment)

github-actions bot pushed a commit that referenced this issue Nov 8, 2024
## [5.25.2](v5.25.1...v5.25.2) (2024-11-08)

### Bug Fixes

* **worker:** allow retrieving concurrency value ([#2883](#2883)) fixes [#2880](#2880) ([52f6317](52f6317))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants