Delayed Job: Configure run_at and max_attempts for a specific job

荒凉一梦 提交于 2019-12-04 19:17:29

问题


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).

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?


回答1:


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

Here's what I did:

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.



来源:https://stackoverflow.com/questions/16226922/delayed-job-configure-run-at-and-max-attempts-for-a-specific-job

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!