Node.js Kue how to restart failed jobs

后端 未结 3 984
孤独总比滥情好
孤独总比滥情好 2020-12-30 04:42

I am using kue for delayed jobs in my node.js application.

I have some problems to figure out how I can restart a job using the API of kue without having to move th

3条回答
  •  醉酒成梦
    2020-12-30 05:29

    This can also be done using queue level events.

    queue.on('job failed', function(id, result) {
        kue.Job.get(id, function(err, job) {
            if (!err && shouldRetry(job))
                job.state('inactive').save();
        });
    });
    

    Thus you don't need to do for every job that you wish to retry. Instead you can filter it in the queue level event.

提交回复
热议问题