-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
32 lines (26 loc) · 1.03 KB
/
main.py
File metadata and controls
32 lines (26 loc) · 1.03 KB
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
import flet as ft
import os
import time
import requests
from views.home import main
HEALTH_URL = "http://model:8000/health"
CHECK_INTERVAL = 5
def wait_for_server():
while True:
try:
resp = requests.get(HEALTH_URL, timeout=2)
if resp.status_code == 200 and resp.json().get("status") == "ok":
print("Servidor listo. Iniciando aplicación Flet...")
return
else:
print(f"Servidor no listo ({resp.status_code}). Reintentando en {CHECK_INTERVAL}s...")
except requests.RequestException as e:
print(f"Esperando la conexión del servidor: {e}. Reintentando en {CHECK_INTERVAL}s...")
time.sleep(CHECK_INTERVAL)
if __name__ == "__main__":
start_time = time.time()
wait_for_server()
total_wait = time.time() - start_time
print(f"Tiempo total de espera hasta que el servidor estuvo listo: {total_wait:.2f} segundos")
port = int(os.getenv("PORT", "5555"))
ft.app(target=main, view=ft.AppView.WEB_BROWSER, port=port)