From 286d45687300a212283fadf33824cd5d3f0b28bb Mon Sep 17 00:00:00 2001 From: Mathias Wolkert Date: Sun, 22 Mar 2020 09:09:41 +0100 Subject: [PATCH] Add logic to retry db connection --- nipap/nipap/backend.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/nipap/nipap/backend.py b/nipap/nipap/backend.py index f8b309226..ae571d736 100644 --- a/nipap/nipap/backend.py +++ b/nipap/nipap/backend.py @@ -786,6 +786,12 @@ def _connect_db(self): self._db_install(db_args['database']) continue raise NipapDatabaseMissingExtensionError("hstore extension not found in the database") + # retry if database is not ready (docker friendly) + if re.search("could not connect to server: Connection refused", unicode(exc)): + self._logger.error("pgsql: %s" % exc) + self._logger.error("Retrying") + time.sleep(1) + continue self._logger.error("pgsql: %s" % exc) raise NipapError("Backend unable to connect to database")