Skip to content

Commit fc55e5b

Browse files
authored
Merge pull request rails#55151 from djmb/active-job-continuations-2
Follow up on Active Job Continuations PR feedback
2 parents b12f586 + 0b88f17 commit fc55e5b

14 files changed

+296
-292
lines changed

activejob/lib/active_job/continuation.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ def instrument_job(event)
315315
end
316316

317317
def instrument(event, payload = {})
318-
job.send(:instrument, event, **payload)
318+
job.instrument event, **payload
319319
end
320320
end
321321
end

activejob/lib/active_job/continuation/step.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,14 @@ def set!(cursor)
4848
# An UnadvanceableCursorError error will be raised if the cursor does not implement +succ+.
4949
def advance!(from: nil)
5050
from = cursor if from.nil?
51-
raise UnadvanceableCursorError, "Cursor class '#{from.class}' does not implement succ, " unless from.respond_to?(:succ)
52-
set! from.succ
51+
52+
begin
53+
to = from.succ
54+
rescue NoMethodError
55+
raise UnadvanceableCursorError, "Cursor class '#{from.class}' does not implement 'succ'"
56+
end
57+
58+
set! to
5359
end
5460

5561
# Has this step been resumed from a previous job execution?

activejob/lib/active_job/instrumentation.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,24 @@ def perform_now
2626
instrument(:perform) { super }
2727
end
2828

29+
def instrument(operation, payload = {}, &block) # :nodoc:
30+
payload[:job] = self
31+
payload[:adapter] = queue_adapter
32+
33+
ActiveSupport::Notifications.instrument("#{operation}.active_job", payload) do
34+
value = block.call if block
35+
payload[:aborted] = @_halted_callback_hook_called if defined?(@_halted_callback_hook_called)
36+
@_halted_callback_hook_called = nil
37+
value
38+
end
39+
end
40+
2941
private
3042
def _perform_job
3143
instrument(:perform_start)
3244
super
3345
end
3446

35-
def instrument(operation, payload = {}, &block)
36-
payload[:job] = self
37-
payload[:adapter] = queue_adapter
38-
39-
ActiveSupport::Notifications.instrument("#{operation}.active_job", payload) do
40-
value = block.call if block
41-
payload[:aborted] = @_halted_callback_hook_called if defined?(@_halted_callback_hook_called)
42-
@_halted_callback_hook_called = nil
43-
value
44-
end
45-
end
46-
4747
def halted_callback_hook(*)
4848
super
4949
@_halted_callback_hook_called = true

0 commit comments

Comments
 (0)