Delayed job not emitting 'complete' #183

pvencill opened this Issue Mar 1, 2013 · 2 comments

2 participants


GIven code like this:

        var email = jobs.create('email', job).save();
    email.on('complete', function(){ console.log('completed',;});
    crawl.on('complete', function(){
            var otherEmail = jobs.create('email', job2).priority('high').delay(30000).save();
            otherEmail.on('promote', function() { console.log('other email promoted');});
            otherEmail.on('complete', function(){ console.log('other email completed');});

    jobs.process('email', doMail);

the otherEmail job emits its 'promoted' event, and it actually runs (that is, the code in the doMail function runs for both jobs), but it does not ever fire the 'complete' event handler code that I assigned.  I can also watch its progress through the kue app, and see that it moves correctly from Active to Completed at appropriate times.  Just my custom handler code doesn't fire.  Anything I"m doing wrong?

still not sure why the above didn't work, but by listening to on('job complete') of the queue instance I was able to do what I wanted.

@pvencill pvencill closed this Apr 16, 2013

Please try to bind your event handlers before you save the job, to prevent races So check if this works better:

 var email = jobs.create('email', job);
 email.on('complete', function(){ console.log('completed',;}).save();
@behrad behrad reopened this Jan 18, 2014
@behrad behrad closed this Jan 27, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment