Spaces:
Runtime error
Runtime error
File size: 946 Bytes
1deb8b6 0b7bc90 1deb8b6 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
import os, time, requests
# Wait a bit for uvicorn to become available
port = int(os.getenv("PORT", "7860"))
base = f"http://127.0.0.1:{port}"
for _ in range(60):
try:
r = requests.get(f"{base}/healthz", timeout=1)
if r.status_code == 200:
break
except Exception:
pass
time.sleep(1)
# Ensure DB created by hitting a simple endpoint (lazy create_all on import)
try:
requests.get(f"{base}/healthz", timeout=3)
except Exception as e:
print("init_db: healthz failed:", e)
# Create admin if envs are present
email = os.getenv("ADMIN_EMAIL")
password = os.getenv("ADMIN_PASSWORD")
if email and password:
try:
resp = requests.post(f"{base}/auth/bootstrap_admin", json={
"email": email, "password": password
}, timeout=5)
print("bootstrap_admin:", resp.status_code, resp.text[:500])
except Exception as e:
print("bootstrap_admin failed:", e)
|