From c47bcf8a61a5a6793076e8fc213daa23960c8219 Mon Sep 17 00:00:00 2001 From: Victor Huang Date: Mon, 18 May 2015 15:24:19 -0700 Subject: [PATCH 1/3] change Sidekiq::Processor.retry_and_suppress_exceptions to use exponential sleep and change default retry to 5 --- lib/sidekiq/processor.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/sidekiq/processor.rb b/lib/sidekiq/processor.rb index 1274369eb..83dab117f 100644 --- a/lib/sidekiq/processor.rb +++ b/lib/sidekiq/processor.rb @@ -132,7 +132,7 @@ def cloned(ary) # If an exception occurs in the block passed to this method, that block will be retried up to max_retries times. # All exceptions will be swallowed and logged. - def retry_and_suppress_exceptions(max_retries = 2) + def retry_and_suppress_exceptions(max_retries = 5) retry_count = 0 begin yield @@ -140,7 +140,7 @@ def retry_and_suppress_exceptions(max_retries = 2) retry_count += 1 if retry_count <= max_retries Sidekiq.logger.debug {"Suppressing and retrying error: #{e.inspect}"} - sleep(1) + sleep(retry_count * retry_count) retry else handle_exception(e, { :message => "Exhausted #{max_retries} retries"}) From 580cf0d5207fcca8b58898340ac1fbcbc9509fac Mon Sep 17 00:00:00 2001 From: Victor Huang Date: Tue, 19 May 2015 15:05:09 -0700 Subject: [PATCH 2/3] created a method for sleep with retry count for monkey patching --- lib/sidekiq/processor.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/sidekiq/processor.rb b/lib/sidekiq/processor.rb index 83dab117f..2654a3534 100644 --- a/lib/sidekiq/processor.rb +++ b/lib/sidekiq/processor.rb @@ -132,7 +132,7 @@ def cloned(ary) # If an exception occurs in the block passed to this method, that block will be retried up to max_retries times. # All exceptions will be swallowed and logged. - def retry_and_suppress_exceptions(max_retries = 5) + def retry_and_suppress_exceptions(max_retries = 2) retry_count = 0 begin yield @@ -140,12 +140,16 @@ def retry_and_suppress_exceptions(max_retries = 5) retry_count += 1 if retry_count <= max_retries Sidekiq.logger.debug {"Suppressing and retrying error: #{e.inspect}"} - sleep(retry_count * retry_count) + sleep_retry_count(retry_count) retry else handle_exception(e, { :message => "Exhausted #{max_retries} retries"}) end end end + + def sleep_retry_count(retry_count) + sleep(retry_count) + end end end From 3adf949663c8752a68376d27db33aba90b410f6e Mon Sep 17 00:00:00 2001 From: Victor Huang Date: Tue, 19 May 2015 19:08:54 -0700 Subject: [PATCH 3/3] increase method retry_and_suppress_exceptions default retries to 5 --- lib/sidekiq/processor.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/sidekiq/processor.rb b/lib/sidekiq/processor.rb index 2654a3534..c93ea4e83 100644 --- a/lib/sidekiq/processor.rb +++ b/lib/sidekiq/processor.rb @@ -132,7 +132,7 @@ def cloned(ary) # If an exception occurs in the block passed to this method, that block will be retried up to max_retries times. # All exceptions will be swallowed and logged. - def retry_and_suppress_exceptions(max_retries = 2) + def retry_and_suppress_exceptions(max_retries = 5) retry_count = 0 begin yield