diff --git a/lib/sidekiq/job_retry.rb b/lib/sidekiq/job_retry.rb index f2156a32..1e8cf84f 100644 --- a/lib/sidekiq/job_retry.rb +++ b/lib/sidekiq/job_retry.rb @@ -215,7 +215,8 @@ module Sidekiq def retry_in(worker, count, exception) begin - worker.sidekiq_retry_in_block.call(count, exception).to_i + custom_retry_in = worker.sidekiq_retry_in_block.call(count, exception) + custom_retry_in.nil? ? nil : custom_retry_in.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 diff --git a/test/test_retry.rb b/test/test_retry.rb index 8e6c6d14..880abfcb 100644 --- a/test/test_retry.rb +++ b/test/test_retry.rb @@ -247,11 +247,16 @@ class TestRetry < Sidekiq::Test end end + class SpecialError < StandardError + end + class CustomWorkerWithException include Sidekiq::Worker sidekiq_retry_in do |count, exception| case exception + when SpecialError + nil when ArgumentError count * 4 else @@ -280,6 +285,11 @@ class TestRetry < Sidekiq::Test assert_equal 4, handler.__send__(:delay_for, CustomWorkerWithException, 2, StandardError.new) end + it "retries with a default delay and exception in case of configured with nil" do + refute_equal 8, handler.__send__(:delay_for, CustomWorkerWithException, 2, SpecialError.new) + refute_equal 4, handler.__send__(:delay_for, CustomWorkerWithException, 2, SpecialError.new) + end + it "retries with a custom delay without exception" do assert_equal 4, handler.__send__(:delay_for, CustomWorkerWithoutException, 2, StandardError.new) end