def _next(self): """ Create a new connection to database, try one by one all servers. if there is no online servers the RuntimeError will be raised :return: the connection object """ current = self.current time_ = monotonic() blacklist = [] for idx in ((i + current) % self.count for i in range(self.count)): info = self._servers[idx] if info.penalty <= time_: try: return Connection((yield from wsql.connect(loop=self._loop, **info.kwargs)), info) except wsql.Error as e: self.invalidate(info, e) if info.penalty > time_: blacklist.append(info) blacklist.sort(key=lambda x: x.penalty) for info in blacklist: try: return Connection( (yield from wsql.connect(loop=self._loop, **info.kwargs)), info) except wsql.Error as e: self.invalidate(info, e) raise RuntimeError('There is no servers to connect.')
def _next(self): """ Create a new connection to database, try one by one all servers. if there is no online servers the RuntimeError will be raised :return: the connection object """ current = self.current time_ = monotonic() blacklist = [] for idx in ((i + current) % self.count for i in range(self.count)): info = self._servers[idx] if info.penalty <= time_: try: return Connection((yield from wsql.connect(loop=self._loop, **info.kwargs)), info) except wsql.Error as e: self.invalidate(info, e) if info.penalty > time_: blacklist.append(info) blacklist.sort(key=lambda x: x.penalty) for info in blacklist: try: return Connection((yield from wsql.connect(loop=self._loop, **info.kwargs)), info) except wsql.Error as e: self.invalidate(info, e) raise RuntimeError('There is no servers to connect.')
def __next__(self): """ Create a new connection to database, try one by one all servers. if there is no online servers the RuntimeError will be raised :return: the connection object """ current = self.current time_ = monotonic() for idx in ((i + current) % self.count for i in range(self.count)): info = self._servers[idx] if info.penalty < time_: try: return Connection(wsql.connect(**info.kwargs), info) except wsql.Error as e: self.invalidate(info, e) raise RuntimeError('There is no online servers.')