在kue文档中,创建队列和添加作业很容易,但我无法了解作业是如何存储的
var kue = require('kue')
jobs = kue.createQueue();添加作业
jobs.create('email', {
title: 'welcome email for tj'
, to: 'tj@learnboost.com'
, template: 'welcome-email'
}).priority('high').save();这个例子很容易理解,但是,如果我需要更多的选项,比如在这个例子中添加一个广告选项-,ad: 'we are the best'怎么办?
jobs.create('email', {
title: 'welcome email for tj'
, to: 'tj@learnboost.com'
, ad: 'we are the best'
, template: 'welcome-email'
}).priority('high').save();我该怎么做呢?
发布于 2013-07-04 05:44:33
jobs.create的第二个arg是一个可以在job processor中访问的对象。您可以在其中放置任何您想要的字段。一旦你设置好你的处理器,你就可以使用"ad“字段了。
添加到您的示例中:
jobs.process('email', function (job, done) {
var advertOption = job.data.ad;
// Do your emailing stuff, like rendering template and sending...
});如果给出三个参数,则可以指定所需的工作进程数:
jobs.process('email', 1, function (job, done) { // samesame这个associated source很容易阅读,而且有很好的注释
https://stackoverflow.com/questions/15862568
复制相似问题