Simplify waiting for db
This commit is contained in:
parent
ed304f571a
commit
71cac6e269
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue