From 71cac6e2697930904f834f33de06abd23015cd7b Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Thu, 8 Apr 2021 00:09:51 +1000 Subject: [PATCH] Simplify waiting for db --- InvenTree/InvenTree/management/commands/wait_for_db.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/InvenTree/InvenTree/management/commands/wait_for_db.py b/InvenTree/InvenTree/management/commands/wait_for_db.py index 198c5dcf73..8709f5315e 100644 --- a/InvenTree/InvenTree/management/commands/wait_for_db.py +++ b/InvenTree/InvenTree/management/commands/wait_for_db.py @@ -7,7 +7,7 @@ from django.core.management.base import BaseCommand from django.db import connections from django.db.utils import OperationalError -import psycopg2 +from part.models import Part import time @@ -26,8 +26,12 @@ class Command(BaseCommand): try: # get the database with keyword 'default' from settings.py db_conn = connections['default'] + + # Try to read some data from the database + Part.objects.count() + # prints success messge in green self.stdout.write(self.style.SUCCESS('InvenTree database connected')) - except (OperationalError, psycopg2.OperationalError): + except: self.stdout.write(self.style.ERROR("Database unavailable, waiting 5 seconds ...")) time.sleep(5)