mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 20:16:44 +00:00
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 import connections
|
||||||
from django.db.utils import OperationalError
|
from django.db.utils import OperationalError
|
||||||
|
|
||||||
import psycopg2
|
from part.models import Part
|
||||||
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
@ -26,8 +26,12 @@ class Command(BaseCommand):
|
|||||||
try:
|
try:
|
||||||
# get the database with keyword 'default' from settings.py
|
# get the database with keyword 'default' from settings.py
|
||||||
db_conn = connections['default']
|
db_conn = connections['default']
|
||||||
|
|
||||||
|
# Try to read some data from the database
|
||||||
|
Part.objects.count()
|
||||||
|
|
||||||
# prints success messge in green
|
# prints success messge in green
|
||||||
self.stdout.write(self.style.SUCCESS('InvenTree database connected'))
|
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 ..."))
|
self.stdout.write(self.style.ERROR("Database unavailable, waiting 5 seconds ..."))
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user