lykmapipo / kue-scheduler

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

Resuming from missed schedule #44

Closed Konkrad closed 7 years ago

Konkrad commented 8 years ago

Currently it doesn't look like kue-scheduler resumes from an schedule which is already over. For me the desired behavior would be that this event fires when the first client connects and a new interval gets set.

//create.js
var kue = require('kue-scheduler');
var Queue = kue.createQueue();
var data = {ms: "Lorem Ipsum"}
var job = Queue
            .createJob('test', data)
            .unique('test')
Queue.every('30 seconds', job)
//process.js
var kue = require('kue-scheduler');
var Queue = kue.createQueue();

Queue.process('test', function(job, done) {
    console.log(`${job.id} - ${new Date().toLocaleTimeString()} - ${job.data.ms}`)
    done();
});

When I start create.js, kill it after it created the job and start process.js within 30 seconds everything works well. If starting process.js after the 30 seconds nothing happens.

gmcnaught commented 8 years ago

This is because redis pubsub does not replay if a pubsub message is missed.

I'm actually working on a function to check all kue schedules in redis and reschedule any missed right now - I can send in a PR when I get that working.

@lykmapipo does it make sense to add that as a part of the queue constructor, or would you prefer that to be a separate, explicitly called function?

lykmapipo commented 8 years ago

Hello,

As of now kue-scheduler doesn't have a mechanism to re-fire key that have already expiry as it relies on redis key expiry events.

So if you schedule and cancel for a time larger than your schedule time then you will miss the job in your process worker.

On 26 Jul 2016 01:17, "Konrad" notifications@github.com wrote:

Currently it doesn't look like kue-scheduler resumes from an schedule which is already over. For me the desired behavior would be that this event fires when the first client connects and a new interval gets set.

//create.jsvar kue = require('kue-scheduler');var Queue = kue.createQueue();var data = {ms: "Lorem Ipsum"}var job = Queue .createJob('test', data) .unique('test')Queue.every('30 seconds', job)

//process.jsvar kue = require('kue-scheduler');var Queue = kue.createQueue(); Queue.process('test', function(job, done) { console.log(${job.id} - ${new Date().toLocaleTimeString()} - ${job.data.ms}) done(); });

When I start create.js, kill it after it created the job and start process.js within 30 seconds everything works well. If starting process.js after the 30 seconds nothing happens.

— 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/44, or mute the thread https://github.com/notifications/unsubscribe-auth/ABiUaSFTo4c5bbaHEdWVPrCtmfVTuopMks5qZTYKgaJpZM4JUmrZ .

marshauf commented 8 years ago

Is it possible to remove the job descriptions from redis but keep the job instances? If so, does kue-scheduler reuse the existing job instances when recreating the jobs?

I got the job descriptions in another database and based on them I create jobs in kue-scheduler. Is there a possible workaround for "resuming from missed schedule"?

fruch commented 7 years ago

Looks like i'm hitting this when I'm trying to test redis connectivity i.e. when I'm disconnecting from redis while the schdule should worked, and reconnecting it.

can you provide some example on how to to recover from redis disconnect. do we need to recreate the jobs ? or what exactly ?

lykmapipo commented 7 years ago

@gmcnaught should be a separate function that can be called explicitly but also we will pollute the options to allow auto-reschedule.

@gmcnaught can we work on this together. I will appreciate.

fruch commented 7 years ago

@lykmapipo I was able to solve it for my use case (I.e. couple of unique jobs), by connecting the redis 'ready' signal, and recreating the jobs. it would be nice if kue-schedule would emit a ready signal, so you can apply your logic. (Like I did, or re-instate the non-unique jobs), anyhow handling disconnects clearly is a must for a scheduler.

I'll try to send my example next week when I'll be back from vacation. (My wife banned bringing my laptop...)

I thanks for the quick responses.

lykmapipo commented 7 years ago

@fruch I will appreciate the hook.

Thanks.

fruch commented 7 years ago

see #63 for my example.