From 1124d3874e69387455a7df92c011d08d5b460681 Mon Sep 17 00:00:00 2001 From: marax Date: Thu, 4 Nov 2021 17:29:34 +0100 Subject: [PATCH] Modified __init.py__ to __init__.py --- app1/management/__init__.py | 0 app1/management/commands/__init__.py | 0 app1/management/commands/wait_for_db.py | 30 +++++++++++++++++++++++++ 3 files changed, 30 insertions(+) create mode 100644 app1/management/__init__.py create mode 100644 app1/management/commands/__init__.py create mode 100644 app1/management/commands/wait_for_db.py diff --git a/app1/management/__init__.py b/app1/management/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app1/management/commands/__init__.py b/app1/management/commands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/app1/management/commands/wait_for_db.py b/app1/management/commands/wait_for_db.py new file mode 100644 index 0000000..f6be870 --- /dev/null +++ b/app1/management/commands/wait_for_db.py @@ -0,0 +1,30 @@ +""" +Django command to wait until DB is started + +""" + +import time + +from psycopg2 import OperationalError as Psycopg2OpError +from django.db.utils import OperationalError + +from django.core.management.base import BaseCommand + +class Command(BaseCommand): + """ Django wait for DB""" + self.stdout.write('Waiting for Database ...') + db_up = False + while db_up is False: + try: + self.check(database=['default']) + db_up = True + except (Psycopg2OpError, OperationalError): + self.stdout.write('Database unavailable, waiting 1 sec...') + time.sleep(1) + + self.stdout.write(self.style.SUCCESS('database ready !!')) + + + + +