延迟的作业:为特定作业配置run_at和max_attempts [英] Delayed Job: Configure run_at and max_attempts for a specific job

查看:92
本文介绍了延迟的作业:为特定作业配置run_at和max_attempts的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于一项特定的工作,我需要覆盖 Delayed :: Worker.max_attempts ,我想重试很多次。另外,我也不想以指数形式确定下一个计划的时间(从文档:5秒+ N ** 4,其中N是重试次数)。

I need to overwrite the Delayed::Worker.max_attempts for one specific job, which I want to retry a lot of times. Also, I don't want the next scheduled time to be determined exponentially (From the docs: 5 seconds + N ** 4, where N is the number of retries).

我不想覆盖 Delayed :: Worker 设置并影响其他作业。

I don't want to overwrite the Delayed::Worker settings, and affect other jobs.

我的作业已经是自定义作业(我以某种方式处理错误),因此可能会有所帮助。

My job is already a custom job (I handle errors in a certain way), so that might be helpful. Any pointers on how to do this?

推荐答案

我通过浏览 delayed_job 源代码。这在他们的文档中没有任何记录。

I figured it out by looking through delayed_job source code. This is not documented anywhere in their docs.

这是我所做的:

class MyCustomJob < Struct.new(:param1, :param2)
  def perform
    # do something
  end

  # attempts and time params are required by delayed_job
  def reschedule_at(time, attempts)
    30.seconds.from_now
  end

  def max_attempts
    50
  end
end

希望这对以后的工作有所帮助。

Hope this helps someone in the future.

这篇关于延迟的作业:为特定作业配置run_at和max_attempts的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆