jwa*_*ags 16
我有一个类似的问题,我基本上想出了以下内容.如果其他人有不同的解决方案,我很乐意看到其他一些想法.
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();
});
Run Code Online (Sandbox Code Playgroud)
Kue的文档很少,但源代码评论很好且易于阅读
| 归档时间: |
|
| 查看次数: |
5193 次 |
| 最近记录: |