Skip to content

Commit 3dfb7ea

Browse files
committed
Don’t require a custom retry check block on all Retryable instances
1 parent f0831dc commit 3dfb7ea

3 files changed

Lines changed: 15 additions & 23 deletions

File tree

lib/userlist/push/strategies/direct.rb

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,7 @@ def client
1919
end
2020

2121
def retryable
22-
@retryable ||= Userlist::Retryable.new do |error|
23-
case error
24-
when Userlist::RequestError
25-
status = error.status
26-
status >= 500 || status == 429
27-
when Userlist::TimeoutError
28-
true
29-
else
30-
false
31-
end
32-
end
22+
@retryable ||= Userlist::Retryable.new
3323
end
3424
end
3525
end

lib/userlist/push/strategies/threaded/worker.rb

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,7 @@ def client
4646
end
4747

4848
def retryable
49-
@retryable ||= Userlist::Retryable.new do |error|
50-
case error
51-
when Userlist::RequestError
52-
status = error.status
53-
status >= 500 || status == 429
54-
when Userlist::TimeoutError
55-
true
56-
else
57-
false
58-
end
59-
end
49+
@retryable ||= Userlist::Retryable.new
6050
end
6151
end
6252
end

lib/userlist/retryable.rb

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,24 @@ class Retryable
77
MULTIPLIER = 2
88
MAX_DELAY = 10_000
99

10+
DEFAULT_RETRY_CHECK = lambda do |error|
11+
case error
12+
when Userlist::RequestError
13+
status = error.status
14+
status >= 500 || status == 429
15+
when Userlist::TimeoutError
16+
true
17+
else
18+
false
19+
end
20+
end
21+
1022
def initialize(retries: RETRIES, delay: DELAY, max_delay: MAX_DELAY, multiplier: MULTIPLIER, &retry_check)
1123
@retries = retries
1224
@delay = delay
1325
@max_delay = max_delay
1426
@multiplier = multiplier
15-
@retry_check = retry_check
27+
@retry_check = retry_check || DEFAULT_RETRY_CHECK
1628
end
1729

1830
def retry?(value)

0 commit comments

Comments
 (0)