kue-scheduler icon indicating copy to clipboard operation
kue-scheduler copied to clipboard

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

Open agordeev opened this issue 7 years ago • 5 comments

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.

agordeev avatar Aug 04 '16 07:08 agordeev

@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.

chrisforrette avatar Aug 12 '16 22:08 chrisforrette

@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/

mmarshak avatar Jan 17 '17 22:01 mmarshak

There is only one server in my environment.

agordeev avatar Jan 18 '17 08:01 agordeev

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 [email protected] 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 .

gmcnaught avatar Jan 18 '17 15:01 gmcnaught

@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.

mmarshak avatar Jan 19 '17 22:01 mmarshak