Make sure job instrumentation keep return value

The implementaiton of `instrument` in `ActiveJob::Instrumentation` was
not keeping the API of `ActiveSupport::Notification.instrument` and
returning the value of the block.

Fixes #40931.
This commit is contained in:
Rafael Mendonça França 2020-12-28 05:30:30 +00:00
parent b4abba3f1e
commit 68b471c4dd
No known key found for this signature in database
GPG Key ID: FC23B6D0F1EEE948
3 changed files with 8 additions and 3 deletions

View File

@ -18,11 +18,14 @@ module ActiveJob
private
def instrument(operation, payload = {}, &block)
enhanced_block = ->(event_payload) do
block.call if block
value = block.call if block
if defined?(@_halted_callback_hook_called) && @_halted_callback_hook_called
event_payload[:aborted] = true
@_halted_callback_hook_called = nil
end
value
end
ActiveSupport::Notifications.instrument \

View File

@ -12,7 +12,7 @@ class RescueTest < ActiveSupport::TestCase
test "rescue perform exception with retry" do
job = RescueJob.new("david")
job.perform_now
assert_equal [ "rescued from ArgumentError", "performed beautifully" ], JobBuffer.values
assert_equal [ "rescued from ArgumentError", "performed beautifully", "Retried job DIFFERENT!" ], JobBuffer.values
end
test "let through unhandled perform exception" do

View File

@ -8,7 +8,9 @@ class RescueJob < ActiveJob::Base
rescue_from(ArgumentError) do
JobBuffer.add("rescued from ArgumentError")
arguments[0] = "DIFFERENT!"
retry_job
job = retry_job
JobBuffer.add("Retried job #{job.arguments[0]}")
job
end
rescue_from(ActiveJob::DeserializationError) do |e|