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

fix(worker): allow retrieving concurrency value #2883

Merged
merged 4 commits into from
Nov 8, 2024

Conversation

fgozdz
Copy link
Contributor

@fgozdz fgozdz commented Nov 5, 2024

No description provided.

@fgozdz fgozdz requested a review from manast November 5, 2024 11:01
@manast manast requested a review from roggervalf November 5, 2024 14:11
Copy link
Contributor

@manast manast left a comment

Choose a reason for hiding this comment

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

LGTM

@@ -395,6 +395,10 @@ export class Worker<
this.opts.concurrency = concurrency;
}

get concurrency() {
return this.opts.concurrency;
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is a bug where this.opts.concurrency should not be set, instead it should be this.concurrency = concurrency at line 395. opts should be immutable as we threat other options like priority or delay. If you change that line, this getter may not be needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is resulting in unending recursion: "RangeError: Maximum call stack size exceeded"

Copy link
Contributor

Choose a reason for hiding this comment

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

@fgozdz what @roggervalf means is that we should not replace this.opts.concurrency as this is mutating the opts object which was passed in the constructor. Instead you can define a private property like _concurrency, and use this instead of this.opts.concurrency. In the constructor you set _concurrency to a default value if this.opts.concurrency is not defined.

Copy link
Contributor

Choose a reason for hiding this comment

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

Honestly speaking It would be far mote elegant to have a explicit setter like "setConcurrency" instead of an implicit setter, but this would imply a breaking change, so we cannot do that now.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@fgozdz you can try doing:

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._concurrency = concurrency;
  }

  get concurrency(): number {
    return this._concurrency;
  }

on worker constructor you may need to replace https://github.com/taskforcesh/bullmq/blob/master/src/classes/worker.ts#L241 as:
this._concurrency = this.opts.concurrency;
and add a private attribute type after this one https://github.com/taskforcesh/bullmq/blob/master/src/classes/worker.ts#L182 like:
private _concurrency:number;
also in order to use this new attribute you should replace this.opts.concurrency to use this._concurrency at worker level

@fgozdz
Copy link
Contributor Author

fgozdz commented Nov 5, 2024

This issue fixes #2880

@fgozdz fgozdz marked this pull request as ready for review November 5, 2024 15:22
@fgozdz fgozdz requested a review from roggervalf November 5, 2024 15:46
Copy link
Collaborator

@roggervalf roggervalf left a comment

Choose a reason for hiding this comment

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

Lgtm, thank you

@roggervalf roggervalf force-pushed the worker-concurrency-getter branch from c59d59d to cb1fb5e Compare November 7, 2024 14:16
@roggervalf roggervalf changed the title feat(worker): getter for a concurrency fix(worker): allow retrieving concurrency value Nov 8, 2024
@roggervalf roggervalf merged commit 52f6317 into master Nov 8, 2024
12 checks passed
@roggervalf roggervalf deleted the worker-concurrency-getter branch November 8, 2024 02:16
github-actions bot pushed a commit that referenced this pull request 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
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants