How to schedule work once on Thursday with Kue?

Using Kue , how do I schedule a task every Thursday? The Kue readme mentions that I can postpone the job, but what about doing the job multiple times at a specific time?

I can do what I want with cron, but I like the Kue functions.

What I want is to process the task once at any time on Thursday, but only once.

+7
source share
2 answers

I had a similar question and basically came up with the following. If anyone else has a different solution, I would like to see some other ideas.

var jobQueue = kue.createQueue(); // Define job processor jobQueue.process('thursday-jobs', function (job, done) { var milisecondsTillThurs = // TODO: Get the time until next thursday. For this I used moment.js // do this job again next Thursday jobQueue.create('thursday-jobs').delay(milisecondsTillThurs).save(); // For Example purpose this job waits then calls done setTimeout(function () { done(); }, 10000); }); // Use some initialization code to check if the job exists yet, and create it otherwise kue.Job.rangeByType('thursday-jobs','delayed', 0, 10, '', function (err, jobs) { if (err) {return handleErr(err);} if (!jobs.length) { jobQueue.create('thursday-jobs').save(); } // Start checking for delayed jobs. This defaults to checking every 5 seconds jobQueue.promote(); }); 

Kue has minimal documentation, but the source is well commented and easy to read.

+14
source

Take a look at kue-scheduler. I am sure you can do something like this:

 var kue = require('kue-scheduler'); var Queue = kue.createQueue(); //create a job instance var job = Queue .createJob('every', data) .attempts(3) .backoff(backoff) .priority('normal'); //schedule it to run every Thursday at 00:00:00 var thursday = '0 0 0 * * 4'; Queue.every(thursday, job); //somewhere process your scheduled jobs Queue.process('every', function(job, done) { ... done(); }); 

kue-scheduler docs: https://github.com/lykmapipo/kue-scheduler ; link in their documents to cron stuff: https://github.com/kelektiv/node-cron ;

0
source

All Articles