Skip to content

Commit

Permalink
fix: use default when returned 0
Browse files Browse the repository at this point in the history
  • Loading branch information
dsalahutdinov authored and mperham committed Mar 22, 2018
1 parent 611f7cd commit 7448351
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions lib/sidekiq/job_retry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class Skip < ::RuntimeError; end
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)
Expand Down Expand Up @@ -205,7 +206,11 @@ def retry_attempts_from(msg_retry, default)
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
Expand All @@ -215,11 +220,10 @@ def seconds_to_delay(count)

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

Expand Down
2 changes: 1 addition & 1 deletion test/test_retry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ class CustomWorkerWithException
sidekiq_retry_in do |count, exception|
case exception
when SpecialError
nil
Sidekiq::JobRetry::USE_DEFAULT_RETRY_FORMULA
when ArgumentError
count * 4
else
Expand Down

0 comments on commit 7448351

Please sign in to comment.