質問

From the kue docs,creating a queue and adding job is is easy but i cannot follow how the job is being stored

var kue = require('kue')
  jobs = kue.createQueue();

adding a job

jobs.create('email', {
    title: 'welcome email for tj'
  , to: 'tj@learnboost.com'
  , template: 'welcome-email'
}).priority('high').save();

The example is easy to understand but,what if i needed more options for instance in the example,like adding an advert option - , 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();

how am i going to go about it?.

役に立ちましたか?

解決

The second arg to jobs.create is an object that will be accessible in the job processor. You can put whatever fields you want in there. Then once you setup your processor you can use the "ad" field.

Adding to your example:

jobs.process('email', function (job, done) {
    var advertOption = job.data.ad;

    // Do your emailing stuff, like rendering template and sending...

});

You can specify the number of workers you want if you give three args:

jobs.process('email', 1, function (job, done) { // samesame

The associated source is easy to read through and well commented

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top