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

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 private
def instrument(operation, payload = {}, &block) def instrument(operation, payload = {}, &block)
enhanced_block = ->(event_payload) do enhanced_block = ->(event_payload) do
block.call if block value = block.call if block
if defined?(@_halted_callback_hook_called) && @_halted_callback_hook_called if defined?(@_halted_callback_hook_called) && @_halted_callback_hook_called
event_payload[:aborted] = true event_payload[:aborted] = true
@_halted_callback_hook_called = nil @_halted_callback_hook_called = nil
end end
value
end end
ActiveSupport::Notifications.instrument \ ActiveSupport::Notifications.instrument \

View file

@ -12,7 +12,7 @@ class RescueTest < ActiveSupport::TestCase
test "rescue perform exception with retry" do test "rescue perform exception with retry" do
job = RescueJob.new("david") job = RescueJob.new("david")
job.perform_now 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 end
test "let through unhandled perform exception" do test "let through unhandled perform exception" do

View file

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