Skip to content

Commit

Permalink
Add a subclass of Retry providing linear backoff time
Browse files Browse the repository at this point in the history
Signed-off-by: Wieland Hoffmann <[email protected]>
  • Loading branch information
mineo committed Jun 4, 2016
1 parent d5eb1b5 commit 880e77b
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions musicbrainzngs/musicbrainz.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,27 @@
_version = "0.7dev"
_log = logging.getLogger("musicbrainzngs")

_retry = Retry(total=8,
status_forcelist=[500, 502, 503],
backoff_factor=0.1)

class MBRetry(Retry):
"""Retry class whose backoff time is::
{ number of observed errors } * 2.0
"""

def get_backoff_time(self):
""" Formula for computing the current backoff
:rtype: float
"""
if self._observed_errors == 0:
return 0

return self._observed_errors * 2.0


_retry = MBRetry(total=8,
status_forcelist=[500, 502, 503])

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

Expand Down

0 comments on commit 880e77b

Please sign in to comment.