简体   繁体   English

Node.js Kue如何重启失败的作业

[英]Node.js Kue how to restart failed jobs

I am using kue for delayed jobs in my node.js application. 我在我的node.js应用程序中使用kue来延迟作业。

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. 我有一些问题要弄清楚如何使用kue的API重新启动作业,而不必使用redis命令手动将作业的ID从失败的作业列表移动到非活动作业列表。

Is this possible using kue? 这可能使用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 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. 但是,Kue允许您指定这一点,这对于转移电子邮件等工作非常重要,如果失败,通常可以在没有问题的情况下重试。 To do this invoke the .attempts() method with a number. 为此,请使用数字调用.attempts()方法。

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

reference: failure attempts 参考: 失败尝试

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM