store and expose reconnection timers on IRCBot.reconnections
This commit is contained in:
parent
85efd75518
commit
19d8f0b497
1 changed files with 7 additions and 1 deletions
|
@ -40,6 +40,7 @@ class Bot(object):
|
||||||
self.start_time = time.time()
|
self.start_time = time.time()
|
||||||
self.running = False
|
self.running = False
|
||||||
self.servers = {}
|
self.servers = {}
|
||||||
|
self.reconnections = {}
|
||||||
|
|
||||||
self._event_queue = queue.Queue() # type: typing.Queue[TriggerEvent]
|
self._event_queue = queue.Queue() # type: typing.Queue[TriggerEvent]
|
||||||
|
|
||||||
|
@ -217,6 +218,8 @@ class Bot(object):
|
||||||
if not self.reconnect(event["server_id"],
|
if not self.reconnect(event["server_id"],
|
||||||
event.get("connection_params", None)):
|
event.get("connection_params", None)):
|
||||||
event["timer"].redo()
|
event["timer"].redo()
|
||||||
|
else:
|
||||||
|
del self.reconnections[event["server_id"]]
|
||||||
def reconnect(self, server_id: int, connection_params: typing.Optional[
|
def reconnect(self, server_id: int, connection_params: typing.Optional[
|
||||||
utils.irc.IRCConnectionParameters]=None) -> bool:
|
utils.irc.IRCConnectionParameters]=None) -> bool:
|
||||||
args = {} # type: typing.Dict[str, str]
|
args = {} # type: typing.Dict[str, str]
|
||||||
|
@ -387,8 +390,11 @@ class Bot(object):
|
||||||
|
|
||||||
if not self.get_server_by_id(server.id):
|
if not self.get_server_by_id(server.id):
|
||||||
reconnect_delay = self.config.get("reconnect-delay", 10)
|
reconnect_delay = self.config.get("reconnect-delay", 10)
|
||||||
self._timers.add("reconnect", reconnect_delay,
|
|
||||||
|
timer = self._timers.add("reconnect", reconnect_delay,
|
||||||
server_id=server.id)
|
server_id=server.id)
|
||||||
|
self.reconnections[server.id] = timer
|
||||||
|
|
||||||
self.log.warn(
|
self.log.warn(
|
||||||
"Disconnected from %s, reconnecting in %d seconds",
|
"Disconnected from %s, reconnecting in %d seconds",
|
||||||
[str(server), reconnect_delay])
|
[str(server), reconnect_delay])
|
||||||
|
|
Loading…
Reference in a new issue