diff options
author | yuuji.yaginuma <yuuji.yaginuma@gmail.com> | 2018-05-09 18:20:54 +0900 |
---|---|---|
committer | Yuji Yaginuma <yuuji.yaginuma@gmail.com> | 2018-05-12 13:55:25 +0900 |
commit | 6fac9bd599eeb6b9cacdf7841811223402c501bd (patch) | |
tree | 0a743c8463000daa620bbc95b8e98f0005f2ece0 | |
parent | 0018e68b5de0bcca3c567ef0141c8b8a35783a0f (diff) | |
download | rails-6fac9bd599eeb6b9cacdf7841811223402c501bd.tar.gz rails-6fac9bd599eeb6b9cacdf7841811223402c501bd.tar.bz2 rails-6fac9bd599eeb6b9cacdf7841811223402c501bd.zip |
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
-rw-r--r-- | activejob/CHANGELOG.md | 6 | ||||
-rw-r--r-- | activejob/lib/active_job/exceptions.rb | 2 | ||||
-rw-r--r-- | activejob/test/cases/exceptions_test.rb | 2 | ||||
-rw-r--r-- | activejob/test/jobs/retry_job.rb | 2 |
4 files changed, 9 insertions, 3 deletions
diff --git a/activejob/CHANGELOG.md b/activejob/CHANGELOG.md index a3d13ad162..dcb9d27f45 100644 --- a/activejob/CHANGELOG.md +++ b/activejob/CHANGELOG.md @@ -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, diff --git a/activejob/lib/active_job/exceptions.rb b/activejob/lib/active_job/exceptions.rb index ae700848d0..31bbb18d7f 100644 --- a/activejob/lib/active_job/exceptions.rb +++ b/activejob/lib/active_job/exceptions.rb @@ -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 diff --git a/activejob/test/cases/exceptions_test.rb b/activejob/test/cases/exceptions_test.rb index bc33d79f61..15938e3fc7 100644 --- a/activejob/test/cases/exceptions_test.rb +++ b/activejob/test/cases/exceptions_test.rb @@ -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 diff --git a/activejob/test/jobs/retry_job.rb b/activejob/test/jobs/retry_job.rb index 82b80fe12b..56c9a78a2e 100644 --- a/activejob/test/jobs/retry_job.rb +++ b/activejob/test/jobs/retry_job.rb @@ -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 |