lykmapipo / kue-scheduler

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

every # sec does not work as expected with multiple workers #110

Open sudhirbitsgoa opened 6 years ago

sudhirbitsgoa commented 6 years ago

Hi,

var kue = require('kue-scheduler');
var Queue = kue.createQueue({
  restore: true
});

//create a job instance
var job = Queue
            .createJob('every', {time:'every 10 secs'})
            .attempts(3)
            // .backoff(backoff)
            .priority('normal')
            .save(function(err) {
              console.log('the err', err)
              console.log(job.id);
            })

//schedule it to run every 2 seconds
Queue.every('10 seconds', job);

the above will act as publisher. Run this and this will create a recurring job with some id. And you can stop this process


var kue = require('kue-scheduler');
var Queue = kue.createQueue({
  restore: true,
  worker: true
});

Queue.process('every', function(job, done) {
  done();
  console.log(job.data);
});
let i=0
setInterval(() => {
  console.log(i++);
}, 1000)

In other file copy this code and run this. As expected for every 10s a job is pushed to queue and finised.

But if we run above code in multiple terminals at same time, the jobs are pushed at random intervals not 10s. This is weird behaviour.

sudhirbitsgoa commented 6 years ago

if i set to unique job then it works.