提交 6fac9bd5 编写于 作者: Y yuuji.yaginuma 提交者: Yuji Yaginuma

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
上级 0018e68b
* Pass the error instance as the second parameter of block executed by `discard_on`.
Fixes #32853.
*Yuji Yaginuma*
* Remove support for Qu gem. * Remove support for Qu gem.
Reasons are that the Qu gem wasn't compatible since Rails 5.1, Reasons are that the Qu gem wasn't compatible since Rails 5.1,
......
...@@ -79,7 +79,7 @@ def retry_on(exception, wait: 3.seconds, attempts: 5, queue: nil, priority: nil) ...@@ -79,7 +79,7 @@ def retry_on(exception, wait: 3.seconds, attempts: 5, queue: nil, priority: nil)
def discard_on(exception) def discard_on(exception)
rescue_from exception do |error| rescue_from exception do |error|
if block_given? if block_given?
yield self, exception yield self, error
else 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 #{exception}. The original exception was #{error.cause.inspect}."
end end
......
...@@ -61,7 +61,7 @@ class ExceptionsTest < ActiveJob::TestCase ...@@ -61,7 +61,7 @@ class ExceptionsTest < ActiveJob::TestCase
test "custom handling of discarded job" do test "custom handling of discarded job" do
perform_enqueued_jobs do perform_enqueued_jobs do
RetryJob.perform_later "CustomDiscardableError", 2 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
end end
......
...@@ -20,7 +20,7 @@ class RetryJob < ActiveJob::Base ...@@ -20,7 +20,7 @@ class RetryJob < ActiveJob::Base
retry_on CustomWaitTenAttemptsError, wait: ->(executions) { executions * 2 }, attempts: 10 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}") } 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 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) def perform(raising, attempts)
if executions < attempts if executions < attempts
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册