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.

30 lines
684 B

  1. """
  2. Django command to wait until DB is started
  3. """
  4. import time
  5. from psycopg2 import OperationalError as Psycopg2OpError
  6. from django.db.utils import OperationalError
  7. from django.core.management.base import BaseCommand
  8. class Command(BaseCommand):
  9. """ Django wait for DB"""
  10. self.stdout.write('Waiting for Database ...')
  11. db_up = False
  12. while db_up is False:
  13. try:
  14. self.check(database=['default'])
  15. db_up = True
  16. except (Psycopg2OpError, OperationalError):
  17. self.stdout.write('Database unavailable, waiting 1 sec...')
  18. time.sleep(1)
  19. self.stdout.write(self.style.SUCCESS('database ready !!'))

Powered by TurnKey Linux.