1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Pass the error instance as the second parameter of block executed by discard_on

I'm not sure what originally wanted to pass to the argument.
However, as long as see the document added along with the commit, it seems just
to be mistaken that trying to pass the error instance.
https://github.com/rails/rails/pull/30622/files#diff-59beb0189c8c6bc862edf7fdb84ff5a7R64

Fixes #32853
This commit is contained in:
yuuji.yaginuma 2018-05-09 18:20:54 +09:00 committed by Yuji Yaginuma
parent 0018e68b5d
commit 6fac9bd599
4 changed files with 9 additions and 3 deletions

View file

@ -1,3 +1,9 @@
* Pass the error instance as the second parameter of block executed by `discard_on`.
Fixes #32853.
*Yuji Yaginuma*
* Remove support for Qu gem.
Reasons are that the Qu gem wasn't compatible since Rails 5.1,

View file

@ -79,7 +79,7 @@ module ActiveJob
def discard_on(exception)
rescue_from exception do |error|
if block_given?
yield self, exception
yield self, error
else
logger.error "Discarded #{self.class} due to a #{exception}. The original exception was #{error.cause.inspect}."
end

View file

@ -61,7 +61,7 @@ class ExceptionsTest < ActiveJob::TestCase
test "custom handling of discarded job" do
perform_enqueued_jobs do
RetryJob.perform_later "CustomDiscardableError", 2
assert_equal "Dealt with a job that was discarded in a custom way", JobBuffer.last_value
assert_equal "Dealt with a job that was discarded in a custom way. Message: CustomDiscardableError", JobBuffer.last_value
end
end

View file

@ -20,7 +20,7 @@ class RetryJob < ActiveJob::Base
retry_on CustomWaitTenAttemptsError, wait: ->(executions) { executions * 2 }, attempts: 10
retry_on(CustomCatchError) { |job, exception| JobBuffer.add("Dealt with a job that failed to retry in a custom way after #{job.arguments.second} attempts. Message: #{exception.message}") }
discard_on DiscardableError
discard_on(CustomDiscardableError) { |job, exception| JobBuffer.add("Dealt with a job that was discarded in a custom way") }
discard_on(CustomDiscardableError) { |job, exception| JobBuffer.add("Dealt with a job that was discarded in a custom way. Message: #{exception.message}") }
def perform(raising, attempts)
if executions < attempts