-
Notifications
You must be signed in to change notification settings - Fork 868
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
job's complete event triggered after processing of next job already began #806
Comments
Good timing! We just encountered a flavor of this and I think we've figured this out. The most relevant code is in worker.js:
In the createDoneCallback of processing, we mark the job complete and then emit the event. This is async. So, by the time event is fired, the next job could be in progress. We ran into this because we listen for job complete and remove the jobs, but this may not work for an active job when a pause/shutdown is applied. When we pause a worker, it will 1) complete its job, 2) call self.start, 3) emit the idle event, and 4) emit the job complete. Elsewhere, the shutdown listener will hear the idle event first, mark the worker as cleaned up, and will fail to emit the job complete. So, maybe we should put the start into the complete/attempt callback, or emit the complete outside, or something else. Haven't thought about it too deeply. You'll be happy to know the processing of your jobs is happening in order, even if the completion events come a little late. |
My vote would be to put job.complete(function() {
job.attempt(function() {
if( job.removeOnComplete() ) {
job.remove();
}
self.emitJobEvent('complete', job, result);
self.start(fn);
});
}.bind(this)); |
You guys can create a tested PR ? |
Happy, behrad. Happy to. |
@dindurthy for me it's more about what @tobalsgithub said: I have to make sure that the previous job is completely done before starting the next one. In my case I have 3 events that are creating jobs ( |
I'm trying to build jobs that depend on another job successfully finishing before running but ran into the problem that when these events happen at the "same time", the first job is not yet marked as completed when the new job gets processed.
example output:
so when I check the completed jobs at the beginning of
queue.process()
thestart
job is not yet returned 😞anyone else having this problem?
The text was updated successfully, but these errors were encountered: