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
|
# Preset each server in this file
|
||||||
for server in config.servers:
|
for server in config.servers:
|
||||||
srv = server.server(config)
|
|
||||||
# Add the server in the context
|
# Add the server in the context
|
||||||
if context.add_server(srv):
|
for i in [0,1,2,3]:
|
||||||
logger.info("Server '%s' successfully added.", srv.name)
|
srv = server.server(config, trynb=i)
|
||||||
else:
|
try:
|
||||||
logger.error("Can't add server '%s'.", srv.name)
|
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
|
# Load module and their configuration
|
||||||
for mod in config.modules:
|
for mod in config.modules:
|
||||||
|
@ -33,7 +33,7 @@ class Server:
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def server(self, parent):
|
def server(self, parent, trynb=0):
|
||||||
from nemubot.server import factory
|
from nemubot.server import factory
|
||||||
|
|
||||||
for a in ["nick", "owner", "realname", "encoding"]:
|
for a in ["nick", "owner", "realname", "encoding"]:
|
||||||
@ -42,4 +42,4 @@ class Server:
|
|||||||
|
|
||||||
self.caps += parent.caps
|
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):
|
class SocketServer(_Socket):
|
||||||
|
|
||||||
def __init__(self, host, port, bind=None, **kwargs):
|
def __init__(self, host, port, bind=None, trynb=0, **kwargs):
|
||||||
(family, type, proto, canonname, self._sockaddr) = socket.getaddrinfo(host, port, proto=socket.IPPROTO_TCP)[0]
|
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)
|
super().__init__(fdClass=socket.socket, family=family, type=type, proto=proto, **kwargs)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user