Skip to content

Commit

Permalink
Refactor, changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mperham committed Mar 22, 2018
1 parent 7448351 commit 86ca02f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 2 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ HEAD
- Remove `freeze` calls on String constants. This is superfluous with Ruby
2.3+ and `frozen_string_literal: true`. [#3759]
- Fix use of AR middleware outside of Rails [#3787]
- Sidekiq::Worker `sidekiq_retry_in` block can now return nil or 0 to use
the default backoff delay [#3796, dsalahutdinov]

5.1.1
-----------
Expand Down
11 changes: 5 additions & 6 deletions lib/sidekiq/job_retry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ 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 @@ -206,9 +205,9 @@ def retry_attempts_from(msg_retry, default)
end

def delay_for(worker, count, exception)
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
if worker && worker.sidekiq_retry_in_block
custom_retry_in = retry_in(worker, count, exception).to_i
return custom_retry_in if custom_retry_in > 0
end
seconds_to_delay(count)
end
Expand All @@ -220,10 +219,10 @@ def seconds_to_delay(count)

def retry_in(worker, count, exception)
begin
worker.sidekiq_retry_in_block.call(count, exception).to_i
worker.sidekiq_retry_in_block.call(count, exception)
rescue Exception => e
handle_exception(e, { context: "Failure scheduling retry using the defined `sidekiq_retry_in` in #{worker.class.name}, falling back to default" })
USE_DEFAULT_RETRY_FORMULA
nil
end
end

Expand Down

0 comments on commit 86ca02f

Please sign in to comment.