Skip to content

Commit

Permalink
add ResponseError BUSY retry handling
Browse files Browse the repository at this point in the history
  • Loading branch information
willgraf committed Jul 11, 2019
1 parent 4bcd043 commit c94a8b6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
12 changes: 12 additions & 0 deletions bucket_monitor/redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ def __getattr__(self, name):

def wrapper(*args, **kwargs):
values = list(args) + list(kwargs.values())
values = [str(v) for v in values]
while True:
try:
return redis_function(*args, **kwargs)
Expand All @@ -181,6 +182,17 @@ def wrapper(*args, **kwargs):
str(name).upper(),
' '.join(values), self.backoff)
time.sleep(self.backoff)
except redis.exceptions.ResponseError as err:
# check if redis just needs a backoff
if 'BUSY' in str(err) and 'SCRIPT KILL' in str(err):
self.logger.warning('Encountered %s: %s when calling '
'`%s %s`. Retrying in %s seconds.',
type(err).__name__, err,
str(name).upper(),
' '.join(values), self.backoff)
time.sleep(self.backoff)
else:
raise err
except Exception as err:
self.logger.error('Unexpected %s: %s when calling `%s %s`.',
type(err).__name__, err,
Expand Down
3 changes: 3 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ norecursedirs=
# W503 line break occurred before a binary operator

pep8ignore=* E731

# Enable line length testing with maximum line length of 85
pep8maxlinelength = 85

0 comments on commit c94a8b6

Please sign in to comment.