Created by: xycloud
producer.js
let Q = require('bull');
const rq = new Q('test', {redis: {
port: 6379,
host: 'xxx',
password: 'xxx'
}});
rq.add({hello: 'bull'}, {repeat: {'cron': '*/2 * * * * * *'}});
rq.add({hello: 'world'}, {repeat: {'cron': '*/2 * * * * * *'}});
consumer.js
let Q = require('bull');
const rq = new Q('test', {redis: {
port: 6379,
host: 'xxx',
password: 'xxx'
}});
rq.process(function(job, done) {
console.log(job.data);
done();
});
if we run the consumer.js, only {hello: 'bull'} will be outputted. by add a defined handler name in job opts config, make cron jobs support same cronjob schedule config, then the code can be:
producer.js
let Q = require('bull');
const rq = new Q('test', {redis: {
port: 6379,
host: 'xxx',
password: 'xxx'
}});
rq.add({hello: 'bull'}, {repeat: {'cron': '*/2 * * * * * *'}});
rq.add({hello: 'world'}, {repeat: {'cron': '*/2 * * * * * *'}, handler: '__default__'});