[Question] What calls `throw(:abort)`
calvincchen opened this issue · 2 comments
Hi,
I'm trying to better understand how sidekiq-iteration
works and which signals lead to resumable jobs. I believe the key logic is here. My understanding is that a corresponding throw(:abort)
is necessary to exit the block early, but I wasn't able to find any references in sidekiq
or sidekiq-iteration
? Looking at sidekiq
, UNIX signals are transformed into raise Interrupt
(link). I haven't been able to find the connection between this raise Interrupt
and catch(:abort)
and was hoping for some clarification.
Thanks!
So firstly, catch(:abort) do
will return not only when someone calls throw :abort
, but also when the corresponding block completes its execution.
My understanding is that a corresponding throw(:abort) is necessary to exit the block early
Yeah, this is not documented yet, but when you write something like
class MyJob
def each_iteration(object)
if some_condition?
throw :abort
else
# do normal work
end
end
then this job will be prematurely aborted without further retries. This is the only place where throw :abort
is expected to be raised.
Looking at
sidekiq
, UNIX signals are transformed intoraise Interrupt
(link). I haven't been able to find the connection between thisraise Interrupt
andcatch(:abort)
and was hoping for some clarification.
Yeah, these are raised/rescued and transformed into other errors in sidekiq itself internally
https://github.com/sidekiq/sidekiq/blob/312672deab31c23810a272d1b06c33c84afaf9dd/bin/sidekiq#L31
https://github.com/sidekiq/sidekiq/blob/312672deab31c23810a272d1b06c33c84afaf9dd/lib/sidekiq/cli.rb#L113
https://github.com/sidekiq/sidekiq/blob/312672deab31c23810a272d1b06c33c84afaf9dd/lib/sidekiq/cli.rb#L130-L140
https://github.com/sidekiq/sidekiq/blob/312672deab31c23810a272d1b06c33c84afaf9dd/lib/sidekiq/launcher.rb#L61-L65
https://github.com/sidekiq/sidekiq/blob/312672deab31c23810a272d1b06c33c84afaf9dd/lib/sidekiq/manager.rb#L52-L65
https://github.com/sidekiq/sidekiq/blob/312672deab31c23810a272d1b06c33c84afaf9dd/lib/sidekiq/manager.rb#L44-L50
https://github.com/sidekiq/sidekiq/blob/312672deab31c23810a272d1b06c33c84afaf9dd/lib/sidekiq/processor.rb#L43-L47
When this happens, sidekiq-iteration
detects that sidekiq is stopping and requeues itself, see
sidekiq-iteration/lib/sidekiq_iteration/iteration.rb
Lines 22 to 25 in a1b5313
sidekiq-iteration/lib/sidekiq_iteration/iteration.rb
Lines 185 to 190 in a1b5313
Hope this helps.
Yeah, that cleared up so much. Thanks!