26 lines
876 B
Python
26 lines
876 B
Python
|
|
"""Wartet, bis die DB Connections annimmt."""
|
||
|
|
import time
|
||
|
|
|
||
|
|
from django.core.management.base import BaseCommand
|
||
|
|
from django.db import OperationalError, connections
|
||
|
|
|
||
|
|
|
||
|
|
class Command(BaseCommand):
|
||
|
|
help = "Wartet, bis die Standard-DB verfügbar ist."
|
||
|
|
|
||
|
|
def add_arguments(self, parser):
|
||
|
|
parser.add_argument("--timeout", type=int, default=60)
|
||
|
|
|
||
|
|
def handle(self, *args, **opts):
|
||
|
|
deadline = time.time() + opts["timeout"]
|
||
|
|
while time.time() < deadline:
|
||
|
|
try:
|
||
|
|
connections["default"].ensure_connection()
|
||
|
|
self.stdout.write(self.style.SUCCESS("DB ist bereit."))
|
||
|
|
return
|
||
|
|
except OperationalError:
|
||
|
|
self.stdout.write("warte auf DB...")
|
||
|
|
time.sleep(2)
|
||
|
|
self.stderr.write(self.style.ERROR("DB nach Timeout nicht erreichbar."))
|
||
|
|
raise SystemExit(1)
|