Commit eaeedd2c authored by Caleb Weeks's avatar Caleb Weeks

adding new queue options

parent d3546c88
const BullQueue = require("bull");
var logger=global.bl.logger.get("blacklight-core.queues-bul");
var logger=global.bl.logger.get("blacklight-core.queues-bull");
exports.build = (id, definition = {}) => {
//at a minimum we need a processor
if(definition.process && definition.process.processor){
if(definition.process && (definition.process.processor || definition.deliberatelyNotProcessing)){
return {
init: () => {
const {redis} = global.bl.config.environment;
const {process, events = {}, options = {}} = definition;
const {process, events = {}, options = {}, singleRepeatedJob} = definition;
//create the new Queue object
const queue = new BullQueue(id, Object.assign({}, options, {redis}));
......@@ -34,18 +34,34 @@ exports.build = (id, definition = {}) => {
Object.keys(allEvents).forEach(key => {
queue.on(key, allEvents[key]);
});
if(singleRepeatedJob){
queue.add({}, singleRepeatedJob).catch(e => {
logger.error(`Error adding "singleRepeatedJob" to ${id}`, e);
});
}
return {
addJob(data, jobOptions = {}){
async addJob(data, jobOptions = {}){
if(data){
return queue.add(data, jobOptions);
if(singleRepeatedJob){
throw new Error("Adding jobs to a queue with the 'singleRepeatedJob' option isn't allowed");
}else{
return queue.add(data, jobOptions);
}
}else{
throw new Error("No data provided, refusing to add job");
}
}, getJob(id){
return queue.getJob(id);
},
getDefinition(){
return definition;
},
getBullQueue(){
return queue;
}
};
},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment