Max attempts depending on the error raised

19 views
Skip to first unread message

Louis

unread,
Oct 19, 2022, 8:12:44 AM10/19/22
to delayed_job
Hi guys !

I would like to be able to change the max attempts depending on the error raised :
- when the error raised is kind of CustomError => direct failure
- otherwise => standard DJ error process

Here is how the code could looks like :

class CustomJob

  class CustomError < StandardError; end

  def perform
    if any_attribute_missing?
      raise CustomError, "Missing attribute X"
    end
    process! # may raise other errors
  end

  def max_attempts
    if error === CustomError
      1
    end
  end
end

Thanks,
Louis
Reply all
Reply to author
Forward
0 new messages