Try to connect multiple times (with different servers if any)
Some checks reported errors
continuous-integration/drone/push Build encountered an error
Some checks reported errors
continuous-integration/drone/push Build encountered an error
This commit is contained in:
parent
9f83e5b178
commit
861ca0afdd
@ -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
|
||||
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:
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user