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

Delayed job not emitting 'complete' #183

Closed
pvencill opened this issue Mar 1, 2013 · 2 comments
Closed

Delayed job not emitting 'complete' #183

pvencill opened this issue Mar 1, 2013 · 2 comments

Comments

@pvencill
Copy link

pvencill commented Mar 1, 2013

GIven code like this:

        var email = jobs.create('email', job).save();
    email.on('complete', function(){ console.log('completed',job.to);});
    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.promote();
    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?
@pvencill
Copy link
Author

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.

@behrad
Copy link
Collaborator

behrad commented Jan 18, 2014

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',job.to);}).save();

@behrad behrad reopened this Jan 18, 2014
@behrad behrad closed this as completed Jan 27, 2014
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

No branches or pull requests

2 participants