locally pausing a queue does not work when there are multiple active workers
Created by: josephwarrick
queue.pause(true /* local */);
will never resolve if there is more than one simultaneously active node process working on jobs.
This means that if we try to do
queue.pause(true /* local */).then(function() {
queue.close();
});
our queue will stop processing jobs, but will never close.
This is happening because:
Suppose queueA and queueB are two separate node processes working on the same queue. Suppose they are each processing one job.
If we call queueA.pause(true)
, queueA will count how many jobs are active globally, getting 2.
queueA will then wait for 2 (completed|failed|stalled) events before pausing.
Since queueA is only working on one job, and queueA won't start any more jobs because it is trying to pause, there will only ever be 1 (completed|failed|stalled) event, so queueA will never pause.
I don't think that listening for a (completed|failed|stalled) event globally is a good solution here. Suppose queueB processes two jobs before queueA can finish it's one job. Then queueA would receive two events, even though queueA is still working on it's job, and would pause incorrectly.