I have been using Bull library for our project extensively. Few days back we found the issue while processing job from Bull Queue. We are able to add job in Bull Queue but it fail to process the job. When I checked in taskforce, then we noticed that job gets delayed/failed with empty error response. I think this is happening because worker process is not attached with Queue. Same code works fine if I try restarting process after some times. I am not really sure if this is the issue with Redis or Bull or the way I am using it. The issue is I am able to add the job but job is not processing. (Unexpectedly in some cases only)
Sample Code Snippet:
const BullQueue = require('bull');
class Queue {
constructor(name, connectionName = DBConstant.localRedisConnectionName) {
const options = {};
options.redis = DBConnectionUseCase.getRedisConnectionOptions(connectionName);
this._queue = new BullQueue(name, options);
this._connectionName = connectionName;
this.queueName = name;
}
async initProcessor() {
try {
//TODO: We have noticed that in some cases process does not get attached to Queue.
//We tried adding await here and check result but did not get anything. This needs to be debug.
this._queue.process((job, done) => {
this.process(job, done);
});
}catch(error) {
console.log(`Worker :: ${this.queueName} :: Exception in processor initialisation :: connectionName :: ${this._connectionName} :: Error :: ${error.message} :: ${JSON.stringify(error)}`);
}
console.log(`Worker :: ${this.queueName} :: processor initialised :: connectionName :: ${this._connectionName}`);
}
getQueueName() {
return this.queueName;
}
addJob(data, options) {
console.log(`Worker :: ${this.queueName} :: Job added in Queue :: ${this._connectionName}`);
return this._queue.add(data, options);
}
}
class FetchCustomerData extends Queue{
constructor() {
super(QUEUE_NAME);
}
/**
*
*/
static getInstance() {
if(!queueInstance) {
queueInstance = new FetchCustomerData();
}
return queueInstance;
}
/**
*
*/
initDefaultJob() {
const data = {};
const options = {
// This cron will run in everyday at 12:30AM ISE
repeat: {
cron: '0 20 * * *'
}
};
this.addJob(data, Object.assign({},options, constant.BULL_JOB_OPTIONS));
console.log(`Worker :: ${QUEUE_NAME} :: initial job added :: options :: ${JSON.stringify(Object.assign({},options, constant.BULL_JOB_OPTIONS))}`);
}
/**
*
*/
async process(job, done) {
try {
...
return done(nu;;);
}catch(error) {
console.error(`FetchActivationalUCC.process :: ${uuid} :: Exception :: ${JSON.stringify(error)}`);
return done(error);
}
}
}
How I am using it:
FetchCustomerData.initProcessor();
const res = await FetchCustomerData.addJob({"key": 123});
Package list:
"bull": "3.7.0"
"ioredis": "4.9.0"
"node": v10.15.0