1
0
Fork 0

Try to connect multiple times (with different servers if any)
continuous-integration/drone/push Build encountered an error Details

This commit is contained in:
nemunaire 2023-01-17 21:55:25 +01:00
parent 9f83e5b178
commit 861ca0afdd
3 changed files with 16 additions and 9 deletions

View File

@ -155,12 +155,18 @@ def main():
# Preset each server in this file
for server in config.servers:
srv = server.server(config)
# Add the server in the context
if context.add_server(srv):
logger.info("Server '%s' successfully added.", srv.name)
else:
logger.error("Can't add server '%s'.", srv.name)
for i in [0,1,2,3]:
srv = server.server(config, trynb=i)
try:
if context.add_server(srv):
logger.info("Server '%s' successfully added.", srv.name)
else:
logger.error("Can't add server '%s'.", srv.name)
except:
logger.error("Unable to connect to '%s'.", srv.name)
continue
break
# Load module and their configuration
for mod in config.modules:

View File

@ -33,7 +33,7 @@ class Server:
return True
def server(self, parent):
def server(self, parent, trynb=0):
from nemubot.server import factory
for a in ["nick", "owner", "realname", "encoding"]:
@ -42,4 +42,4 @@ class Server:
self.caps += parent.caps
return factory(self.uri, caps=self.caps, channels=self.channels, **self.args)
return factory(self.uri, caps=self.caps, channels=self.channels, trynb=trynb, **self.args)

View File

@ -79,8 +79,9 @@ class _Socket(AbstractServer):
class SocketServer(_Socket):
def __init__(self, host, port, bind=None, **kwargs):
(family, type, proto, canonname, self._sockaddr) = socket.getaddrinfo(host, port, proto=socket.IPPROTO_TCP)[0]
def __init__(self, host, port, bind=None, trynb=0, **kwargs):
destlist = socket.getaddrinfo(host, port, proto=socket.IPPROTO_TCP)
(family, type, proto, canonname, self._sockaddr) = destlist[trynb%len(destlist)]
super().__init__(fdClass=socket.socket, family=family, type=type, proto=proto, **kwargs)