technoweenie / coffee-resque

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Having several local workers work on the same queue

louisameline opened this issue · comments

I was hoping that a Node instance could handle several jobs of a same type concurrently. Something like this:

// only one worker will accept the "doThis" jobs
var worker = resque.worker('node', {
    doThis: function(){...}
});
workers.push(worker);

// several concurrent workers will accept the  "doThat" jobs
for(var i = 0; i < 5; i++){
    worker = resque.worker('node', {
        doThat: function(){...}
    });
    workers.push(worker);
}

$.each(workers, function(i, worker){
    worker.start();
});

But the doThat jobs fail, saying "error": "Missing Job: doThat". I assume that once a worker is listening to a queue, the others can't anymore. How can I achieve the desired result ?
Thank you.

Nevermind, I get the logic behind this. I'll just use different queues or have several workers that handle all the necessary job types. Thank you

You can have multiple workers performing jobs off the same queue. Plus the worker can perform many jobs. The problem I think you are running into is that you are putting multiple job types in the queue, in that case all workers bound to that queue need to be setup to perform all the various jobs you plan to enqueue.

Check out how I did it here and here.

Something like this should work

var jobs = {
  foo : function(){},
  bar : function(){}
};

// several concurrent workers
for (var i = 0; i < 5; i++) {
  workers.push(resque.worker('queue', jobs));
}

$.each(workers, function(i, worker) { 
  worker.start(); 
});