From 097a53a53946003ee038651a9d40370230d18746 Mon Sep 17 00:00:00 2001 From: Izalia Mae Date: Thu, 22 Feb 2024 13:44:58 -0500 Subject: [PATCH] ensure cache is setup --- relay/application.py | 3 +++ relay/cache.py | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/relay/application.py b/relay/application.py index f7007b0..cf9611b 100644 --- a/relay/application.py +++ b/relay/application.py @@ -61,9 +61,12 @@ class Application(web.Application): self['database'] = get_database(self.config) self['client'] = HttpClient() self['cache'] = get_cache(self) + self['cache'].setup() self['push_queue'] = multiprocessing.Queue() self['workers'] = [] + self.cache.setup() + self.on_response_prepare.append(handle_access_log) self.on_cleanup.append(handle_cleanup) diff --git a/relay/cache.py b/relay/cache.py index 448267f..5647106 100644 --- a/relay/cache.py +++ b/relay/cache.py @@ -231,7 +231,7 @@ class SqlCache(Cache): def setup(self) -> None: - if self._db.connected: + if self._db and self._db.connected: return self._db = get_database(self.app.config) @@ -243,6 +243,9 @@ class SqlCache(Cache): def close(self) -> None: + if not self._db: + return + self._db.disconnect() self._db = None @@ -351,5 +354,8 @@ class RedisCache(Cache): def close(self) -> None: + if not self._rd: + return + self._rd.close() self._rd = None