From 440def6f3ca03e589c66cb20483b4fc015e2b9e2 Mon Sep 17 00:00:00 2001 From: "Gavin M. Roy" Date: Wed, 8 Jul 2020 14:34:41 -0400 Subject: [PATCH] Dont create objects if we do not need to --- sprockets_postgres.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/sprockets_postgres.py b/sprockets_postgres.py index 07278fb..9063985 100644 --- a/sprockets_postgres.py +++ b/sprockets_postgres.py @@ -480,12 +480,13 @@ class ApplicationMixin: callback mechanism. """ - self._postgres_connected = asyncio.Event() - self._postgres_reconnect = asyncio.Lock() - if 'POSTGRES_URL' not in os.environ: LOGGER.critical('Missing POSTGRES_URL environment variable') return self.stop(loop) + + self._postgres_connected = asyncio.Event() + self._postgres_reconnect = asyncio.Lock() + if not await self._postgres_connect(): LOGGER.critical('PostgreSQL failed to connect, shutting down') return self.stop(loop)