1
0
Fork 0
mirror of https://github.com/mperham/sidekiq.git synced 2022-11-09 13:52:34 -05:00

fix: use default when returned 0

This commit is contained in:
Salahutdinov Dmitry 2018-03-21 19:31:03 +05:00 committed by Mike Perham
parent 611f7cd31f
commit 7448351d73
2 changed files with 9 additions and 5 deletions

View file

@ -61,6 +61,7 @@ module Sidekiq
include Sidekiq::Util
DEFAULT_MAX_RETRY_ATTEMPTS = 25
USE_DEFAULT_RETRY_FORMULA = 0
def initialize(options = {})
@max_retries = Sidekiq.options.merge(options).fetch(:max_retries, DEFAULT_MAX_RETRY_ATTEMPTS)
@ -205,7 +206,11 @@ module Sidekiq
end
def delay_for(worker, count, exception)
worker && worker.sidekiq_retry_in_block && retry_in(worker, count, exception) || seconds_to_delay(count)
if worker && worker.sidekiq_retry_in_block
custom_retry_in = retry_in(worker, count, exception)
return custom_retry_in if custom_retry_in != USE_DEFAULT_RETRY_FORMULA
end
seconds_to_delay(count)
end
# delayed_job uses the same basic formula
@ -215,11 +220,10 @@ module Sidekiq
def retry_in(worker, count, exception)
begin
custom_retry_in = worker.sidekiq_retry_in_block.call(count, exception)
custom_retry_in.nil? ? nil : custom_retry_in.to_i
worker.sidekiq_retry_in_block.call(count, exception).to_i
rescue Exception => e
handle_exception(e, { context: "Failure scheduling retry using the defined `sidekiq_retry_in` in #{worker.class.name}, falling back to default" })
nil
USE_DEFAULT_RETRY_FORMULA
end
end

View file

@ -256,7 +256,7 @@ class TestRetry < Sidekiq::Test
sidekiq_retry_in do |count, exception|
case exception
when SpecialError
nil
Sidekiq::JobRetry::USE_DEFAULT_RETRY_FORMULA
when ArgumentError
count * 4
else