Skip to content

Commit

Permalink
Don’t require a custom retry check block on all Retryable instances
Browse files Browse the repository at this point in the history
  • Loading branch information
benedikt committed Nov 15, 2024
1 parent f0831dc commit 3dfb7ea
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 23 deletions.
12 changes: 1 addition & 11 deletions lib/userlist/push/strategies/direct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 1 addition & 11 deletions lib/userlist/push/strategies/threaded/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 13 additions & 1 deletion lib/userlist/retryable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 3dfb7ea

Please sign in to comment.