def next(self, message, backoff_exchange_name):
total_attempts = 0
for deadlettered in message.headers.get('x-death', ()):
if deadlettered['exchange'] == backoff_exchange_name:
total_attempts += int(deadlettered['count'])
if self.limit and total_attempts >= self.limit:
expired = Backoff.Expired(
"Backoff aborted after '{}' retries (~{:.0f} seconds)".format(
self.limit, self.max_delay / 1000
)
)
six.raise_from(expired, self)
expiration = self.get_next_schedule_item(total_attempts)
if self.random_sigma:
randomised = int(random.gauss(expiration, self.random_sigma))
group_size = self.random_sigma / self.random_groups_per_sigma
expiration = round_to_nearest(randomised, interval=group_size)
# Prevent any negative values created by randomness
expiration = abs(expiration)
# store calculation results on self.
self._next_expiration = expiration
self._total_attempts = total_attempts
return expiration
评论列表
文章目录