Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

adding a job to a queue in kue

Tags:

node.js

kue

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: '[email protected]'
  , 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: '[email protected]'
  , ad: 'we are the best'
  , template: 'welcome-email'
}).priority('high').save();

how am i going to go about it?.

like image 216
Gandalf Avatar asked Dec 11 '25 20:12

Gandalf


1 Answers

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

like image 180
jwags Avatar answered Dec 14 '25 13:12

jwags



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!