In some applications, some classes of errors may be raised during the execution of a job which the developer would want to retry forever. These classes of errors would most likely be infrastructure problems that the developer knows will be resolved eventually but may take a variable amount of time or errors where due to application business logic, there could be something temporarily blocking the job from executing, like a resource that is needed for the job being locked for a lengthy amount of time. While an arbitrarily large number of attempts could previously be passed, this is inexpressive as sometimes the developer may just need the job to continue to be retried until it eventually succeeds. Without this, developers would need to include additional code to handle the situation where the job eventually fails its attempts limit and has to be re-enqueued manually. As with many things this should be used with caution and only for errors that the developer knows will definitely eventually be resolved, allowing the job to continue. [Daniel Morton + Rafael Mendonça França]
1.9 KiB
-
Allow a job to retry indefinitely
The
attempts
parameter of theretry_on
method now accepts the symbol reference:unlimited
in addition to a specific number of retry attempts to allow a developer to specify that a job should retry forever until it succeeds.class MyJob < ActiveJob::Base retry_on(AlwaysRetryException, attempts: :unlimited) # the actual job code end
Daniel Morton
-
Added possibility to check on
:priority
in test helper methodsassert_enqueued_with
andassert_performed_with
.Wojciech Wnętrzak
-
OpenSSL constants are now used for Digest computations.
Dirkjan Bussink
-
Add a Serializer for the Range class.
This should allow things like
MyJob.perform_later(range: 1..100)
. -
Communicate enqueue failures to callers of
perform_later
.perform_later
can now optionally take a block which will execute after the adapter attempts to enqueue the job. The block will receive the job instance as an argument even if the enqueue was not successful. Additionally,ActiveJob
adapters now have the ability to raise anActiveJob::EnqueueError
which will be caught and stored in the job instance so code attempting to enqueue jobs can inspect any raisedEnqueueError
using the block.MyJob.perform_later do |job| unless job.successfully_enqueued? if job.enqueue_error&.message == "Redis was unavailable" # invoke some code that will retry the job after a delay end end end
Daniel Morton
-
Don't log rescuable exceptions defined with
rescue_from
.Hu Hailin
-
Allow
rescue_from
to rescue all exceptions.Adrianna Chang, Étienne Barrié
Please check 6-1-stable for previous changes.