Rails 7 adds indefinite job retries

Rails 7 introduces a counter-fail measure in the ActiveJob framework. This is an indefinite job retries feature that would solve the different reasons why queued jobs would fail. Some of these reasons could be logical errors in the code, failure in the database, network issues, and queue malfunctions.

The syntax that specifies indefinite runtime for a background job is a great plus especially for developers who are certain that the failures in their defined jobs would eventually be resolved in the future.

Rails 7 onwards

Passing the :unlimited option to the attempts parameter of the retry_on method ensures that the job would always be enqueued in case of any failure.

1
2
3
4
5
6
7
class EmailNotification < ActiveJon::Base
  retry_on AlwaysRetryException, attempts: :unlimited

  def perform()
   # send email to user
  end
end

Caution

This feature should only be used when developers are sure that the failures they are experiencing will be resolved.