Skip to content

Commit 68b471c

Browse files
committed
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 rails#40931.
1 parent b4abba3 commit 68b471c

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

activejob/lib/active_job/instrumentation.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,14 @@ module Instrumentation #:nodoc:
1818
private
1919
def instrument(operation, payload = {}, &block)
2020
enhanced_block = ->(event_payload) do
21-
block.call if block
21+
value = block.call if block
22+
2223
if defined?(@_halted_callback_hook_called) && @_halted_callback_hook_called
2324
event_payload[:aborted] = true
2425
@_halted_callback_hook_called = nil
2526
end
27+
28+
value
2629
end
2730

2831
ActiveSupport::Notifications.instrument \

activejob/test/cases/rescue_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class RescueTest < ActiveSupport::TestCase
1212
test "rescue perform exception with retry" do
1313
job = RescueJob.new("david")
1414
job.perform_now
15-
assert_equal [ "rescued from ArgumentError", "performed beautifully" ], JobBuffer.values
15+
assert_equal [ "rescued from ArgumentError", "performed beautifully", "Retried job DIFFERENT!" ], JobBuffer.values
1616
end
1717

1818
test "let through unhandled perform exception" do

activejob/test/jobs/rescue_job.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ class OtherError < StandardError; end
88
rescue_from(ArgumentError) do
99
JobBuffer.add("rescued from ArgumentError")
1010
arguments[0] = "DIFFERENT!"
11-
retry_job
11+
job = retry_job
12+
JobBuffer.add("Retried job #{job.arguments[0]}")
13+
job
1214
end
1315

1416
rescue_from(ActiveJob::DeserializationError) do |e|

0 commit comments

Comments
 (0)