I'm trying to run two different jobs on different schedules (see code ex below). For some reason, the job that is supposed to run once a day at 11pm runs every time the other job runs. How do I get them to run when I expect them to run? Thank you for your help.
const kue = require('kue-scheduler');
const Queue = kue.createQueue();
const jobOneSchedule = '0 0 23 * * *';
const jobTwoSchedule = '0 0 0/1 * * *';
let job1 = Queue.createJob('doJobOne')
.priority('low')
.unique('unique_one')
.removeOnComplete('true');
let job2 = Queue.createJob('doJobTwo')
.priority('high')
.unique('unique_two')
.removeOnComplete('true');
Queue.every(jobOneSchedule, job1);
Queue.every(jobTwoSchedule, job2);
Queue.process('doJobOne', function(job, done){
console.log('Job one done');
done();
});
Queue.process('doJobTwo', function(job, done){
console.log('Job two through');
done();
});
Workaround
As a workaround, I had to remove all of the job2 stuff and run it like this:
// Do job2 stuff every hour (3.6e6 ms)
const jobTwoInterval = 3.6e6;
setInterval(function(){
console.log('Job two through');
}, jobTwoInterval);
Working fine at my end
Could you try flushing redis and try again.
setInterval has disadvantage that if server restart your job will be never be executed as interval will be cleared.