aboutsummaryrefslogtreecommitdiffstats
path: root/activejob/lib/active_job/exceptions.rb
diff options
context:
space:
mode:
authorGeorge Claghorn <george@basecamp.com>2018-06-25 18:16:58 -0400
committerGeorge Claghorn <george@basecamp.com>2018-06-25 18:16:58 -0400
commit3110caecbebdad7300daaf26bfdff39efda99e25 (patch)
tree7539316cfa54a252d9711854ec230300da73dba4 /activejob/lib/active_job/exceptions.rb
parent83247916c934a92f0f9d69ee13cd8532c3d16d0e (diff)
downloadrails-3110caecbebdad7300daaf26bfdff39efda99e25.tar.gz
rails-3110caecbebdad7300daaf26bfdff39efda99e25.tar.bz2
rails-3110caecbebdad7300daaf26bfdff39efda99e25.zip
Allow passing multiple exceptions to retry_on/discard_on
Diffstat (limited to 'activejob/lib/active_job/exceptions.rb')
-rw-r--r--activejob/lib/active_job/exceptions.rb14
1 files changed, 7 insertions, 7 deletions
diff --git a/activejob/lib/active_job/exceptions.rb b/activejob/lib/active_job/exceptions.rb
index 96b1e262f2..1e57dbcb1c 100644
--- a/activejob/lib/active_job/exceptions.rb
+++ b/activejob/lib/active_job/exceptions.rb
@@ -42,16 +42,16 @@ module ActiveJob
# # Might raise Net::OpenTimeout when the remote service is down
# end
# end
- def retry_on(exception, wait: 3.seconds, attempts: 5, queue: nil, priority: nil)
- rescue_from exception do |error|
+ def retry_on(*exceptions, wait: 3.seconds, attempts: 5, queue: nil, priority: nil)
+ rescue_from(*exceptions) do |error|
if executions < attempts
- logger.error "Retrying #{self.class} in #{wait} seconds, due to a #{exception}. The original exception was #{error.cause.inspect}."
+ logger.error "Retrying #{self.class} in #{wait} seconds, due to a #{error.class}. The original exception was #{error.cause.inspect}."
retry_job wait: determine_delay(wait), queue: queue, priority: priority
else
if block_given?
yield self, error
else
- logger.error "Stopped retrying #{self.class} due to a #{exception}, which reoccurred on #{executions} attempts. The original exception was #{error.cause.inspect}."
+ logger.error "Stopped retrying #{self.class} due to a #{error.class}, which reoccurred on #{executions} attempts. The original exception was #{error.cause.inspect}."
raise error
end
end
@@ -76,12 +76,12 @@ module ActiveJob
# # Might raise CustomAppException for something domain specific
# end
# end
- def discard_on(exception)
- rescue_from exception do |error|
+ def discard_on(*exceptions)
+ rescue_from(*exceptions) do |error|
if block_given?
yield self, error
else
- logger.error "Discarded #{self.class} due to a #{exception}. The original exception was #{error.cause.inspect}."
+ logger.error "Discarded #{self.class} due to a #{error.class}. The original exception was #{error.cause.inspect}."
end
end
end