You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

32 lines
766 B

"""
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"""
def handle(self, *args, **options):
self.stdout.write('Waiting for Database ...')
db_up = False
while db_up is False:
try:
self.check(databases=['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 !!'))

Powered by TurnKey Linux.