2

I can't figure out what I'm doing wrong, perhaps somone can point it out. I'm trying to figure out why my 'job complete' event isn't firing.

var kue = require('kue'),           
jobs = kue.createQueue();
var util= require('util');
var job = jobs.create('test',  util.puts('123')).on('complete', function(){
    console.log("Job complete");
}).on('failed', function(){
    console.log("Job failed");
}).on('progress', function(progress){
    process.stdout.write('\r  job #' + job.id + ' ' + progress + '% complete');
});

Now when I run this on node it prints 123 but it doesn't say job complete.

j0k
  • 22,600
  • 28
  • 79
  • 90
HariSad
  • 31
  • 3

3 Answers3

4

This question is old, but there is still no solution on the internet for those, who encounters this problem even with placing save()... I've made out three steps for myself to solve the problem:

1. Make sure that you call save() method on your jobs AFTER you set handlers on them.

var job = queue.create('some process', some_args);

job.on('complete', function(result) {

  console.log('complete');

}).on('failed', function(result) {

  console.log('failed');

}).removeOnComplete(true).save();

P.S. It's also a good practice to remove jobs on complete, otherwise you'll overfill redis memory.

2. Make sure your handlers are alright.
I myself experimented with event handlers, trying to pass them several arguments. My 'failed' event handler accepted both error code and other data I passed through done(err, data) method. This was not right. So check the documentation and official Kue examples to make sure your code isn't bugged.

3. If nothing helps, execute redis-cli flushall in your terminal.
And BEWARE!!! This will delete everything in your redis. I'm myself noob in it, so it is used only as a dependency for Kue on my system. I don't know definitely, but I suppose that this can destroy your data you may use in redis. Though it somehow fixes the problem, when nothing more helps.

Everyone, please, feel free to suggest any other secure ways to fix Kue with redis.

P.S. Haven't check, but I suppose, that changing process name for your jobs (it's 'some process' in my example) can also workaround the problem.

mvlabat
  • 577
  • 4
  • 17
  • how to return success from process – user269867 Oct 09 '17 at 21:39
  • @user269867, sorry, I would be glad to help, but I didn't understand your question. Where do you want to return "success"? How and for what do you want to handle that return value? You should clarify. Anyway, this sounds like an another SO question – mvlabat Oct 11 '17 at 09:09
1

I think you need to run job.save() after the .create is executed.

James
  • 5,137
  • 5
  • 40
  • 80
1

As @James mentions you must call .save() after the event handlers has been set.

See the example.

Community
  • 1
  • 1
webjay
  • 5,358
  • 9
  • 45
  • 62