lykmapipo / kue-scheduler

A job scheduler utility for kue, backed by redis and built for node.js
246 stars 47 forks source link

Schedule and processing multiple jobs on Heroku #71

Closed promisenxu closed 7 years ago

promisenxu commented 7 years ago

I'm trying to use kue-scheduler to recurringly run some functions. Detailed situations:

What I have done is scheduling all the jobs in the main process and process all the jobs in a separate work process.

However I discovered that only the last job called with "queue.process" will be invoked. This seems to be a hard limit for kue, i.e. only one job can be processed in each work instance. Is this true? If so, any recommendation on how I can implement the code to fit my needs?

lykmapipo commented 7 years ago

@promisenxu

Hope it helps.

promisenxu commented 7 years ago

@lykmapipo Thanks for the detailed response.

From what you said:

kue concurrency is limited with how many process you attach in processing the work plus the number of worker you allow per process. So far I found it perform its intended job very well. Cross check of there is any other process where you have invoked queue.process.

So it is true that ONLY one job can be processed per worker instance on heroku? I'm trying to call queue.process() multiple time with different jobs on the same worker instance, not calling queue.process() on multiple worker instances for the same job.

promisenxu commented 7 years ago

@lykmapipo

To further clarify, what I'm trying to do is:

In the main process:

var queue = kue.createQueue({redis:process.env.REDISCLOUD_URL, skipConfig:true});
var job1 = queue.createJob('job1', {});
queue.every('5 seconds', job1);
var job2 = queue.createJob('job2', {});
queue.every('10 seconds', job2);

In the worker process:

var queue = kue.createQueue({redis:process.env.REDISCLOUD_URL, skipConfig:true});
queue.process('job1', function(job, done) {
    // Do something
    console.log('job1 finished);
    done();
});
queue.process('job2', function(job, done) {
    // Do something
    console.log('job2 finished);
    done();
});

With the above example, only job2 will ever be processed. I want job1 and job2 (and many other jobs, in my production environment) to both be processed. I'm not sure how to achieve that.

promisenxu commented 7 years ago

@lykmapipo I seemed to have solved my problem - I was using a for loop in my actual code to schedule and process all the jobs. There were a scope problem with the variables. I fixed that and everything is working fine now. Thank you for your help!