diff --git a/lib/userlist/push/strategies/direct.rb b/lib/userlist/push/strategies/direct.rb index 088681d..627dba6 100644 --- a/lib/userlist/push/strategies/direct.rb +++ b/lib/userlist/push/strategies/direct.rb @@ -19,17 +19,7 @@ def client end def retryable - @retryable ||= Userlist::Retryable.new do |error| - case error - when Userlist::RequestError - status = error.status - status >= 500 || status == 429 - when Userlist::TimeoutError - true - else - false - end - end + @retryable ||= Userlist::Retryable.new end end end diff --git a/lib/userlist/push/strategies/threaded/worker.rb b/lib/userlist/push/strategies/threaded/worker.rb index 8a054d3..e01975a 100644 --- a/lib/userlist/push/strategies/threaded/worker.rb +++ b/lib/userlist/push/strategies/threaded/worker.rb @@ -46,17 +46,7 @@ def client end def retryable - @retryable ||= Userlist::Retryable.new do |error| - case error - when Userlist::RequestError - status = error.status - status >= 500 || status == 429 - when Userlist::TimeoutError - true - else - false - end - end + @retryable ||= Userlist::Retryable.new end end end diff --git a/lib/userlist/retryable.rb b/lib/userlist/retryable.rb index 41e5edd..9980739 100644 --- a/lib/userlist/retryable.rb +++ b/lib/userlist/retryable.rb @@ -7,12 +7,24 @@ class Retryable MULTIPLIER = 2 MAX_DELAY = 10_000 + DEFAULT_RETRY_CHECK = lambda do |error| + case error + when Userlist::RequestError + status = error.status + status >= 500 || status == 429 + when Userlist::TimeoutError + true + else + false + end + end + def initialize(retries: RETRIES, delay: DELAY, max_delay: MAX_DELAY, multiplier: MULTIPLIER, &retry_check) @retries = retries @delay = delay @max_delay = max_delay @multiplier = multiplier - @retry_check = retry_check + @retry_check = retry_check || DEFAULT_RETRY_CHECK end def retry?(value)