From 1e1d57f6294eb7c3a8d9a0c76c77eb10c43b3ebe Mon Sep 17 00:00:00 2001 From: Thomas Petersson Date: Fri, 27 Nov 2020 16:00:19 +0100 Subject: fix(bot): PR reivew of bot.py --- bot/bot.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/bot/bot.py b/bot/bot.py index b097513f1..bcce4a118 100644 --- a/bot/bot.py +++ b/bot/bot.py @@ -53,20 +53,22 @@ class Bot(commands.Bot): def _connect_statsd(self, statsd_url: str, retry_after: int = 2, attempt: int = 1) -> None: """Callback used to retry a connection to statsd if it should fail.""" - if self._statsd_timerhandle and not self._statsd_timerhandle.cancelled: - self._statsd_timerhandle.cancel() - - if attempt >= 5: - log.error("Reached 5 attempts trying to reconnect AsyncStatsClient. Aborting") + if attempt >= 8: + log.error("Reached 8 attempts trying to reconnect AsyncStatsClient. Aborting") return try: self.stats = AsyncStatsClient(self.loop, statsd_url, 8125, prefix="bot") except socket.gaierror: log.warning(f"Statsd client failed to connect (Attempt(s): {attempt})") - # Use a fallback strategy for retrying, up to 5 times. + # Use a fallback strategy for retrying, up to 8 times. self._statsd_timerhandle = self.loop.call_later( - retry_after, self._connect_statsd, statsd_url, retry_after * 5, attempt + 1) + retry_after, + self._connect_statsd, + statsd_url, + retry_after * 2, + attempt + 1 + ) async def cache_filter_list_data(self) -> None: """Cache all the data in the FilterList on the site.""" @@ -172,7 +174,7 @@ class Bot(commands.Bot): if self.redis_session: await self.redis_session.close() - if self._statsd_timerhandle and not self._statsd_timerhandle.cancelled: + if self._statsd_timerhandle: self._statsd_timerhandle.cancel() def insert_item_into_filter_list_cache(self, item: Dict[str, str]) -> None: -- cgit v1.2.3