Merge "Use wait_random_exponential from tenacity 4.4.0"

This commit is contained in:
Zuul 2018-03-27 18:24:13 +00:00 committed by Gerrit Code Review
commit e1aa04bf86
1 changed files with 1 additions and 24 deletions

View File

@ -115,34 +115,11 @@ def serialize_input_data(input_data):
return {'input_data': _serialize(input_data)}
class wait_random_exponential(tenacity.wait_exponential):
"""Random wait strategy with a geometrically increasing amount of jitter.
Implements the truncated binary exponential backoff algorithm as used in
e.g. CSMA media access control. The retry occurs at a random time in a
(geometrically) expanding interval constrained by minimum and maximum
limits.
"""
def __init__(self, min=0, multiplier=1, max=tenacity._utils.MAX_WAIT,
exp_base=2):
super(wait_random_exponential, self).__init__(multiplier=multiplier,
max=(max-min),
exp_base=exp_base)
self._random = tenacity.wait_random(min=min, max=(min + multiplier))
def __call__(self, previous_attempt_number, delay_since_first_attempt):
jitter = super(wait_random_exponential,
self).__call__(previous_attempt_number,
delay_since_first_attempt)
self._random.wait_random_max = self._random.wait_random_min + jitter
return self._random(previous_attempt_number, delay_since_first_attempt)
def sync(cnxt, entity_id, current_traversal, is_update, propagate,
predecessors, new_data):
# Retry waits up to 60 seconds at most, with exponentially increasing
# amounts of jitter per resource still outstanding
wait_strategy = wait_random_exponential(max=60)
wait_strategy = tenacity.wait_random_exponential(max=60)
def init_jitter(existing_input_data):
nconflicts = max(0, len(predecessors) - len(existing_input_data) - 1)