我正在编写一个nodeJS keu进程。我的要求是,如果我的队列检查数据库行每20秒更新5次。如果条件更新成功,如果更新1-5任意次数,它将停止完整的队列过程,但重试方法n将再次运行。
这是队列生成函数
var job = queue.create('email', {
id: 1,
}).attempts(5).save( function(err){
if( !err ) console.log( job.id );
});
job.on('complete', function(result){
console.log('Job completed with data ', result);
}).on('failed attempt', function(errorMessage, doneAttempts){
console.log('Job failed',doneAttempts);
}).on('failed', function(errorMessage){
console.log('Job failed',errorMessage);
}).on('progress', function(progress, data){
console.log('\r job #' + job.id + ' ' + progress + '% complete with data ', data );
});
这是队列处理功能
var email = async (information, done)=> {
var dummy = await DummyService.getRecord(information.id);
if(dummy.receiver_id!=0){
done(dummy);
}
return done(new Error('something wrong'));
});
// others wise retry after 20 second