lykmapipo / kue-scheduler

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

kue-scheduler doesn't respect interval - fires a job more often, than set #45

Open agordeev opened 8 years ago

agordeev commented 8 years ago

Here's my code:

var kue = require('kue-scheduler');
var Queue = kue.createQueue();
var jobName = "sendReport";

// Create a job instance in the queue.
var job = Queue
            .createJob(jobName)
            .priority('normal')
            .removeOnComplete(true);

// Schedule it to run every 60 minutes. Function every(interval, job) accepts interval in either a human-interval String format or a cron String format.
Queue.every('60 minutes', job);

Queue.process(jobName, sendReport);

function sendReport(job, done) {
    ....
}

Before this I had interval set to 10 seconds with the same job name for testing purposes. Now I changed it to 60 minutes and restarted the app. However, my job fires much more often than once in an hour. Does kue keep queue persistent between the app launches? How should I handle this case? The only workaround I found is to change jobName.

chrisforrette commented 8 years ago

@andrew8712 I've been bitten by this one too—job name change works and so does running a FLUSHALL command against your Redis DB, but it also nukes all the data in there.

mmarshak commented 7 years ago

@andrew8712 do you run on a single server or multiple servers? If I run on a single node server the very works correctly, but in case of multiple servers (let say 3) the every fire x3 times. Don't use ever in multi server environment until the repo will fix that/

agordeev commented 7 years ago

There is only one server in my environment.

gmcnaught commented 7 years ago

kue.every uses redis itself to handling the recurring schedule - in kue to re-schedule a job, you need to delete that job first before re-adding by the same name.

Also @mmarshak a hangup that bites people with this is that every server will schedule, setting the job as unique should work in a multi-server environment at this time, and ensures multiple instances don't get scheduled - but I do have a feature request in that may make that more flexible.

On Wed, Jan 18, 2017 at 3:02 AM, Andrey Gordeev notifications@github.com wrote:

There is only one server in my environment.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/lykmapipo/kue-scheduler/issues/45#issuecomment-273408688, or mute the thread https://github.com/notifications/unsubscribe-auth/ABTsf2O2pVOXLB8ui_DBhDF324oDZ80Cks5rTccVgaJpZM4Jcboj .

mmarshak commented 7 years ago

@gmcnaught I tested it with node with 3 server running at the same time with 'every' with and without unique and the job was created multiple times instead of once.