diff options
author | 2022-04-18 16:58:01 +0100 | |
---|---|---|
committer | 2022-04-18 16:58:01 +0100 | |
commit | 4b93fbb03d22134cab1f9d9f1f07e5f81012dea5 (patch) | |
tree | 4470bc87711d79de0be2680b52a618005c86f1c4 /botcore | |
parent | Merge pull request #56 from python-discord/minor-fixes-to-BotBase (diff) | |
parent | Reconnect to redis session on setup if it is closed (diff) |
Merge pull request #61 from python-discord/redis-reconnect-on-setupv5.0.3
Reconnect to redis session on setup if it is closed
Diffstat (limited to 'botcore')
-rw-r--r-- | botcore/_bot.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/botcore/_bot.py b/botcore/_bot.py index e69b056d..69ccdc1c 100644 --- a/botcore/_bot.py +++ b/botcore/_bot.py @@ -222,6 +222,11 @@ class BotBase(commands.Bot): ) self.http.connector = self._connector + if getattr(self, "redis_session", False) and self.redis_session.closed: + # If the RedisSession was somehow closed, we try to reconnect it + # here. Normally, this shouldn't happen. + await self.redis_session.connect() + # Create dummy stats client first, in case `statsd_url` is unreachable within `_connect_statsd()` self.stats = AsyncStatsClient(loop, "127.0.0.1") self._connect_statsd(self.statsd_url, loop) @@ -265,7 +270,7 @@ class BotBase(commands.Bot): if self.stats._transport: self.stats._transport.close() - if getattr(self.redis_session, None): + if getattr(self, "redis_session", False): await self.redis_session.close() if self._statsd_timerhandle: |