Skip to content

Commit 880e77b

Browse files
committed
Add a subclass of Retry providing linear backoff time
Signed-off-by: Wieland Hoffmann <themineo@gmail.com>
1 parent d5eb1b5 commit 880e77b

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

musicbrainzngs/musicbrainz.py

+21-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,27 @@
2323
_version = "0.7dev"
2424
_log = logging.getLogger("musicbrainzngs")
2525

26-
_retry = Retry(total=8,
27-
status_forcelist=[500, 502, 503],
28-
backoff_factor=0.1)
26+
27+
class MBRetry(Retry):
28+
"""Retry class whose backoff time is::
29+
30+
{ number of observed errors } * 2.0
31+
32+
"""
33+
34+
def get_backoff_time(self):
35+
""" Formula for computing the current backoff
36+
37+
:rtype: float
38+
"""
39+
if self._observed_errors == 0:
40+
return 0
41+
42+
return self._observed_errors * 2.0
43+
44+
45+
_retry = MBRetry(total=8,
46+
status_forcelist=[500, 502, 503])
2947

3048
LUCENE_SPECIAL = r'([+\-&|!(){}\[\]\^"~*?:\\\/])'
3149

0 commit comments

Comments
 (0)