-
Notifications
You must be signed in to change notification settings - Fork 435
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
refactor(pause): stop run execution #3046
base: master
Are you sure you want to change the base?
Conversation
d2dedbd
to
a7c8d1c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure this is correct. When the worker is paused it must be awaiting something otherwise it will loop at maximum speed doing nothing consuming all the CPU.
src/classes/worker.ts
Outdated
@@ -476,6 +475,9 @@ export class Worker< | |||
numTotal < this._concurrency && | |||
(!this.limitUntil || numTotal == 0) | |||
) { | |||
if (this.paused) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be moved to the while loop condition expression instead.
@@ -582,11 +584,7 @@ export class Worker< | |||
{ block = true }: GetNextJobOptions = {}, | |||
): Promise<Job<DataType, ResultType, NameType> | undefined> { | |||
if (this.paused) { | |||
if (block) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There could be a reason why we block here, it could be that the loop will run super fast doing nothing consuming all the CPU, this needs to be properly tested.
I modified the test case to verify that runExecution is resolved after pausing |
ec03b53
to
c36a209
Compare
Why
How
Additional Notes (Optional)
Notice that we wait for pending jobs in https://github.com/taskforcesh/bullmq/blob/master/src/classes/worker.ts#L954 when pausing a worker by default, but we can possibly add paused promise into async queue https://github.com/taskforcesh/bullmq/blob/master/src/classes/worker.ts#L586, that means that we can get pause method hanging