From f33a0ad369cedd56aa45da76fd28b7398614a757 Mon Sep 17 00:00:00 2001 From: jesopo Date: Sun, 26 Apr 2020 01:19:16 +0100 Subject: [PATCH] add ConnectionParams.reconnect - we'll use this for exponential backoff --- ircrobots/bot.py | 5 ++--- ircrobots/params.py | 2 ++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/ircrobots/bot.py b/ircrobots/bot.py index 5f92819..e6836d5 100644 --- a/ircrobots/bot.py +++ b/ircrobots/bot.py @@ -8,8 +8,6 @@ from .server import ConnectionParams, Server from .transport import TCPTransport from .interface import IBot, IServer -RECONNECT_DELAY = 10.0 # ten seconds reconnect - class Bot(IBot): def __init__(self): self.servers: Dict[str, Server] = {} @@ -20,8 +18,9 @@ class Bot(IBot): return Server(self, name) async def disconnected(self, server: IServer): if (server.name in self.servers and + server.params is not None and server.disconnected): - await asyncio.sleep(RECONNECT_DELAY) + await asyncio.sleep(server.params.reconnect) await self.add_server(server.name, server.params) # /methods designed to be overridden diff --git a/ircrobots/params.py b/ircrobots/params.py index 9c8d54f..269687e 100644 --- a/ircrobots/params.py +++ b/ircrobots/params.py @@ -45,3 +45,5 @@ class ConnectionParams(object): sts: Optional[STSPolicy] = None resume: Optional[ResumePolicy] = None + + reconnect: int = 10 # seconds