最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Node.js Kue how to restart failed jobs - Stack Overflow

programmeradmin4浏览0评论

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 the id of a job manually from the the list of failed jobs to the list of inactive jobs using redis commands.

Is this possible using kue?

I don't want to set a fixed number of retry attempts - I just want to retry specific jobs.

Suggestions for a well maintained alternative to kue are also welcome.

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 the id of a job manually from the the list of failed jobs to the list of inactive jobs using redis commands.

Is this possible using kue?

I don't want to set a fixed number of retry attempts - I just want to retry specific jobs.

Suggestions for a well maintained alternative to kue are also welcome.

Share Improve this question edited Jan 11, 2013 at 15:42 Matthias asked Jan 11, 2013 at 15:11 MatthiasMatthias 6475 silver badges14 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 12

i dont know if this is working but you could try to reset the state of the job to active, and save the job again:

job.on('failed', function() {
  job.state('inactive').save();

Edit: setting state to inactive will correctly re-enqueue the task.

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.

see Failure Attempts in the official docs

By default jobs only have one attempt, that is when they fail, they are marked as a failure, and remain that way until you intervene. However, Kue allows you to specify this, which is important for jobs such as transferring an email, which upon failure, may usually retry without issue. To do this invoke the .attempts() method with a number.

 queue.create('email', {
     title: 'welcome email for tj'
   , to: '[email protected]'
   , template: 'welcome-email'
 }).priority('high').attempts(5).save();

reference: failure attempts

发布评论

评论列表(0)

  1. 暂无评论