Spaces:
Sleeping
Sleeping
Commit ·
e13f209
1
Parent(s): 17168fa
Add service health checks and diagnostics for WebSocket errors
Browse files- app.py +35 -2
- test_services.py +58 -0
app.py
CHANGED
|
@@ -55,6 +55,34 @@ def check_frontend():
|
|
| 55 |
logger.error("❌ Frontend non disponible")
|
| 56 |
return False
|
| 57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
def start_services():
|
| 59 |
"""Démarre tous les services backend."""
|
| 60 |
logger.info("🚀 Démarrage des services backend...")
|
|
@@ -73,7 +101,7 @@ def start_services():
|
|
| 73 |
], cwd=os.getcwd(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
| 74 |
|
| 75 |
# Attendre un peu pour que les services démarrent
|
| 76 |
-
time.sleep(
|
| 77 |
|
| 78 |
# Vérifier que le processus est toujours en vie
|
| 79 |
if process.poll() is not None:
|
|
@@ -83,7 +111,12 @@ def start_services():
|
|
| 83 |
logger.error(f"STDERR: {stderr.decode()}")
|
| 84 |
return False
|
| 85 |
|
| 86 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
return True
|
| 88 |
|
| 89 |
except Exception as e:
|
|
|
|
| 55 |
logger.error("❌ Frontend non disponible")
|
| 56 |
return False
|
| 57 |
|
| 58 |
+
def test_services():
|
| 59 |
+
"""Teste que tous les services backend sont accessibles."""
|
| 60 |
+
logger.info("🔍 Test des services backend...")
|
| 61 |
+
|
| 62 |
+
import requests
|
| 63 |
+
|
| 64 |
+
services = [
|
| 65 |
+
("TTS", "http://localhost:5000/health"),
|
| 66 |
+
("STT", "http://localhost:5001/health"),
|
| 67 |
+
("LLM", "http://localhost:5002/health"),
|
| 68 |
+
("Live Stream", "http://localhost:5003/health"),
|
| 69 |
+
]
|
| 70 |
+
|
| 71 |
+
all_ok = True
|
| 72 |
+
for name, url in services:
|
| 73 |
+
try:
|
| 74 |
+
response = requests.get(url, timeout=5)
|
| 75 |
+
if response.status_code == 200:
|
| 76 |
+
logger.info(f"✅ {name}: OK")
|
| 77 |
+
else:
|
| 78 |
+
logger.error(f"❌ {name}: Erreur (status {response.status_code})")
|
| 79 |
+
all_ok = False
|
| 80 |
+
except Exception as e:
|
| 81 |
+
logger.error(f"❌ {name}: Erreur de connexion - {e}")
|
| 82 |
+
all_ok = False
|
| 83 |
+
|
| 84 |
+
return all_ok
|
| 85 |
+
|
| 86 |
def start_services():
|
| 87 |
"""Démarre tous les services backend."""
|
| 88 |
logger.info("🚀 Démarrage des services backend...")
|
|
|
|
| 101 |
], cwd=os.getcwd(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
| 102 |
|
| 103 |
# Attendre un peu pour que les services démarrent
|
| 104 |
+
time.sleep(15)
|
| 105 |
|
| 106 |
# Vérifier que le processus est toujours en vie
|
| 107 |
if process.poll() is not None:
|
|
|
|
| 111 |
logger.error(f"STDERR: {stderr.decode()}")
|
| 112 |
return False
|
| 113 |
|
| 114 |
+
# Tester que les services sont accessibles
|
| 115 |
+
if not test_services():
|
| 116 |
+
logger.error("❌ Certains services ne sont pas accessibles")
|
| 117 |
+
return False
|
| 118 |
+
|
| 119 |
+
logger.info("✅ Services backend démarrés et testés")
|
| 120 |
return True
|
| 121 |
|
| 122 |
except Exception as e:
|
test_services.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""
|
| 3 |
+
Script de test pour vérifier que tous les services backend sont accessibles
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import requests
|
| 7 |
+
import json
|
| 8 |
+
import time
|
| 9 |
+
|
| 10 |
+
def test_service(name, url, method="GET", data=None):
|
| 11 |
+
"""Teste un service backend"""
|
| 12 |
+
try:
|
| 13 |
+
if method == "GET":
|
| 14 |
+
response = requests.get(url, timeout=5)
|
| 15 |
+
elif method == "POST":
|
| 16 |
+
response = requests.post(url, json=data, timeout=5)
|
| 17 |
+
|
| 18 |
+
if response.status_code == 200:
|
| 19 |
+
print(f"✅ {name}: OK (status {response.status_code})")
|
| 20 |
+
return True
|
| 21 |
+
else:
|
| 22 |
+
print(f"❌ {name}: Erreur (status {response.status_code})")
|
| 23 |
+
return False
|
| 24 |
+
except Exception as e:
|
| 25 |
+
print(f"❌ {name}: Erreur de connexion - {e}")
|
| 26 |
+
return False
|
| 27 |
+
|
| 28 |
+
def main():
|
| 29 |
+
print("🔍 Test des services backend...")
|
| 30 |
+
|
| 31 |
+
services = [
|
| 32 |
+
("TTS Health", "http://localhost:5000/health", "GET"),
|
| 33 |
+
("STT Health", "http://localhost:5001/health", "GET"),
|
| 34 |
+
("LLM Health", "http://localhost:5002/health", "GET"),
|
| 35 |
+
("Live Stream Health", "http://localhost:5003/health", "GET"),
|
| 36 |
+
]
|
| 37 |
+
|
| 38 |
+
all_ok = True
|
| 39 |
+
for name, url, method in services:
|
| 40 |
+
if not test_service(name, url, method):
|
| 41 |
+
all_ok = False
|
| 42 |
+
|
| 43 |
+
if all_ok:
|
| 44 |
+
print("\n🎉 Tous les services sont opérationnels!")
|
| 45 |
+
|
| 46 |
+
# Test d'un service TTS simple
|
| 47 |
+
print("\n🧪 Test TTS...")
|
| 48 |
+
tts_data = {"text": "Test", "lang": "fr"}
|
| 49 |
+
if test_service("TTS Generate", "http://localhost:5000/generate-tts", "POST", tts_data):
|
| 50 |
+
print("✅ TTS fonctionne correctement")
|
| 51 |
+
else:
|
| 52 |
+
print("❌ TTS ne fonctionne pas")
|
| 53 |
+
else:
|
| 54 |
+
print("\n⚠️ Certains services ne sont pas accessibles")
|
| 55 |
+
print("💡 Vérifiez que les services backend sont démarrés")
|
| 56 |
+
|
| 57 |
+
if __name__ == "__main__":
|
| 58 |
+
main()
|