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

Ability to fire onComplete and onFailAttempt events? #105

Open
chrisli30 opened this issue Aug 14, 2017 · 2 comments
Open

Ability to fire onComplete and onFailAttempt events? #105

chrisli30 opened this issue Aug 14, 2017 · 2 comments

Comments

@chrisli30
Copy link

Hi,

I wonder if kue-scheduler has the ability to fire events upon completion, succeed or fail attempts.
Similar to Kue job events.
job.on('complete', function(result) {
console.log('Job completed with data ', result);

        }).on('failed attempt', function(errorMessage, doneAttempts) {
            console.log('Job failed');

        }).on('failed', function(errorMessage) {
            console.log('Job failed');

        }).on('progress', function(progress, data) {
            console.log('\r  job #' + job.id + ' ' + progress + '% complete with data ', data);

        }).on('error',function(err){
            console.log('Job err');
            console.log(err);
        });

Thanks.

@chrisli30
Copy link
Author

Got time to dig deep and figured it out myself. The job object returned from createJob is not the same as the one in process(function(job)). Queue.on('schedule success') has access to the actual job instance and runs after _buildJob in Kue-Scheduler, so we can achieve onComplete and onFail event setup like below.

Queue.on('schedule success', function(job) {
if (jobObj.type === jobName) {
job.on('complete', function(result) {
console.log('Job completed with data ', result);
}).on('failed attempt', function(errorMessage, doneAttempts) {
console.log('Job failed');
}).on('failed', function(errorMessage) {
console.log('Job failed');
}).on('progress', function(progress, data) {
console.log('\r job #' + job.id + ' ' + progress +
'% complete with data ', data);
});
}
});

@chrisli30 chrisli30 reopened this Sep 6, 2017
@lykmapipo
Copy link
Owner

Hello @chrisli30.

Initial implementation for kue-scheduler tried to leave all heavy lifting to kue and thats why we fire events to allow fine hook-points to work with codes that are targeted to kue or more integrations.

Now, are onComplete and onFailAttempt related to job instance or schedules. If its job instance i will appreciate to utilize kue api otherwise we can resonate what to do.

Thanks.

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