2

Using nodejs and kue, I want to insert a long running job into a queue and forget about it. The worker will handle all details.

Short example:

(function(){
  var kue = require('kue');
  var jobs = kue.createQueue();

  var job = jobs.create('email', {
    foo: "bar"
  }).save(function(err){  
    console.log("saved"); 
    jobs.shutdown( function(err){ 
       console.log("shutting down");
    },0); 
  }); 
 }());
 // DOES NOT EXIT

The job is created (and processed separately) but the producers process does not exit without an interrupt signal.

I don't want the producer process to keep resources or connections open. I don't want to listen for job events. I'm hoping for a "fire and forget" type of approach.

Does kue do this? How?

Thanks!

EDIT:

1: To add: lsof -p shows open tcp connections to port 6379 (the redis server)

2: I also tried calling job.client.quit() in the shutdown callback.

mshiltonj
  • 316
  • 3
  • 14

1 Answers1

0

The reason is because the underlying redis client will automatically reconnect whenever the connection is dropped.

You can control this a little by passing some redis config options when creating the kue queue:

kue.createQueue( {redis: { options: { max_attempts: 0 } } } );

Hoever, the max_attempts must be 1 or greater. A value of zero, as in the example above, is ignored:

https://github.com/mranney/node_redis/blob/master/index.js#L50

So, as written (in the redis client), once a connection is opened, it stays open. No matter what I set for max_attempts or how many times I called shutdown() or quit(), a connection is always open until I interrupt the program.

mshiltonj
  • 316
  • 3
  • 14