def _sleep(self, deadline, attempt, exception): now = time.time() seconds_left = deadline - now if seconds_left <= 0: LOG.debug( "Handler %s failed (attempt %s; %s), " "timeout exceeded (%s seconds)", self._handler, attempt, exceptions.format_msg(exception), self._timeout) return 0 interval = random.randint(1, 2**attempt - 1) * self._interval if interval > seconds_left: interval = seconds_left if interval < self._interval: interval = self._interval LOG.debug( "Handler %s failed (attempt %s; %s), " "retrying in %s seconds", self._handler, attempt, exceptions.format_msg(exception), interval) time.sleep(interval) return interval
def _sleep(self, deadline, attempt, exception): LOG.debug("Handler %s failed (attempt %s; %s)", self._handler, attempt, exceptions.format_msg(exception)) interval = utils.exponential_sleep(deadline, attempt, self._interval) if not interval: LOG.debug( "Handler %s failed (attempt %s; %s), " "timeout exceeded (%s seconds)", self._handler, attempt, exceptions.format_msg(exception), self._timeout) return 0 LOG.debug("Resumed after %s seconds. Retry handler %s", interval, self._handler) return interval