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

  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. def handle(self, *args, **options):
  11. self.stdout.write('Waiting for Database ...')
  12. db_up = False
  13. while db_up is False:
  14. try:
  15. self.check(databases=['default'])
  16. db_up = True
  17. except (Psycopg2OpError, OperationalError):
  18. self.stdout.write('Database unavailable, waiting 1 sec...')
  19. time.sleep(1)
  20. self.stdout.write(self.style.SUCCESS('database ready !!'))

Powered by TurnKey Linux.