failover: store result in FailoverException

This commit is contained in:
Jimmy Zelinskie 2017-02-14 14:33:11 -05:00
parent 8a1b48dd8c
commit d2909c0e4d
3 changed files with 11 additions and 9 deletions

View file

@ -8,8 +8,9 @@ logger = logging.getLogger(__name__)
class FailoverException(Exception):
""" Exception raised when an operation should be retried by the failover decorator. """
def __init__(self, message):
def __init__(self, return_value, message):
super(FailoverException, self).__init__()
self.return_value = return_value
self.message = message
def failover(func):
@ -41,6 +42,7 @@ def failover(func):
return func(*arg_set[0], **arg_set[1])
except FailoverException as ex:
logger.debug('failing over: %s', ex.message)
return_value = ex.return_value
continue
raise FailoverException('exhausted all possible failovers')
return return_value
return wrapper