How failure(job) callback work in DelayedJob ?
I want that in my delayed job max_attempts is 5 and after 5 attempts job is failed then call failure(job) callback. In rails 6 or greater.
class MyJob < Struct.new(:some_param)
def perform
# Your job logic here
end
def max_attempts
3 # Set the maximum number of retry attempts
end
def failure(job)
# Define what to do after the maximum failures
handle_failure(job)
end
private
def handle_failure(job)
# Your failure handling logic here
# For example, send an email notification
UserMailer.job_failed_notification(some_param).deliver_now
end
end
Hardi Patel is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.