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:
parent
b4abba3f1e
commit
68b471c4dd
3 changed files with 8 additions and 3 deletions
|
@ -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 \
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -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|
|
||||||
|
|
Loading…
Reference in a new issue