Spaces:
Sleeping
Sleeping
Update Deployment_UI_BE.py
Browse files- Deployment_UI_BE.py +20 -16
Deployment_UI_BE.py
CHANGED
|
@@ -376,7 +376,7 @@ async def api_create_instance(req: Request):
|
|
| 376 |
_INST["port"] = _INST.get("port") or ""
|
| 377 |
return JSONResponse(content, r.status_code)
|
| 378 |
# ---------------------------------------------------------------------
|
| 379 |
-
# Poll / read instance status + explicit readiness fields
|
| 380 |
# ---------------------------------------------------------------------
|
| 381 |
@router.get("/api/compute/pods/{pod_id}")
|
| 382 |
def api_get_instance(pod_id: str = None):
|
|
@@ -424,13 +424,12 @@ def api_get_instance(pod_id: str = None):
|
|
| 424 |
_log_status(f"PORT_MAPPING declared={declared} chosen={chosen} all={pm}")
|
| 425 |
_log_status(f"RESOLVED_ENDPOINT base={base}")
|
| 426 |
|
| 427 |
-
# --- health-first readiness (mirror Vertex), fallback to predict existence ---
|
| 428 |
hr = (_INST.get("healthRoute") or "/health").strip()
|
| 429 |
pr = (_INST.get("predictRoute") or "/predict").strip()
|
| 430 |
|
| 431 |
code_h, ms_h, snippet_h = _probe("GET", f"{base}{hr}")
|
| 432 |
_log_status(f"HEALTH_PROBE path={hr} code={code_h} ms={ms_h} body_snippet={snippet_h[:120]}")
|
| 433 |
-
|
| 434 |
if code_h in (200, 204):
|
| 435 |
_INST["status"] = "READY"
|
| 436 |
else:
|
|
@@ -439,12 +438,17 @@ def api_get_instance(pod_id: str = None):
|
|
| 439 |
if code_p in (200, 204, 400, 405):
|
| 440 |
_INST["status"] = "READY"
|
| 441 |
|
| 442 |
-
#
|
| 443 |
-
|
| 444 |
-
|
| 445 |
prompt_url = f"http://{_INST['ip']}:{_INST['port']}{proute}"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 446 |
_log_status(f"PROMPT_ENDPOINT {prompt_url}")
|
| 447 |
|
|
|
|
| 448 |
merged = {**last, "cachedState": {
|
| 449 |
"podId": _INST.get("podId"),
|
| 450 |
"status": _INST.get("status"),
|
|
@@ -454,7 +458,6 @@ def api_get_instance(pod_id: str = None):
|
|
| 454 |
"healthRoute": _INST.get("healthRoute"),
|
| 455 |
}}
|
| 456 |
return JSONResponse(merged)
|
| 457 |
-
|
| 458 |
# ---------------------------------------------------------------------
|
| 459 |
# Start, Stop, End All — same as before
|
| 460 |
# ---------------------------------------------------------------------
|
|
@@ -507,7 +510,7 @@ async def api_end_all():
|
|
| 507 |
return JSONResponse(status_code=500, content={"error": f"RunPod delete failed: {e}"})
|
| 508 |
|
| 509 |
# ---------------------------------------------------------------------
|
| 510 |
-
# Wait instance
|
| 511 |
# ---------------------------------------------------------------------
|
| 512 |
@router.get("/api/compute/wait_instance")
|
| 513 |
def api_wait_instance(pod_id: str = None):
|
|
@@ -534,23 +537,26 @@ def api_wait_instance(pod_id: str = None):
|
|
| 534 |
pass
|
| 535 |
|
| 536 |
if ip and pm:
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
|
|
|
|
|
|
|
|
|
| 540 |
port = str(pm["8080"])
|
| 541 |
-
elif pm:
|
| 542 |
port = str(pm[next(iter(pm.keys()))])
|
| 543 |
|
| 544 |
if ip and port:
|
| 545 |
base = f"http://{ip}:{port}"
|
| 546 |
_log_status(f"RESOLVED_IP {base}")
|
| 547 |
|
|
|
|
| 548 |
hr = (_INST.get("healthRoute") or "/health").strip()
|
| 549 |
pr = (_INST.get("predictRoute") or "/predict").strip()
|
| 550 |
|
| 551 |
code_h, ms_h, snippet_h = _probe("GET", f"{base}{hr}")
|
| 552 |
_log_status(f"HEALTH_PROBE path={hr} code={code_h} ms={ms_h} body_snippet={snippet_h[:120]}")
|
| 553 |
-
|
| 554 |
if code_h in (200, 204):
|
| 555 |
_INST["status"] = "READY"
|
| 556 |
else:
|
|
@@ -562,7 +568,6 @@ def api_wait_instance(pod_id: str = None):
|
|
| 562 |
if _INST.get("predictRoute"):
|
| 563 |
_log_status(f"PROMPT_ENDPOINT {base}{_INST['predictRoute']}")
|
| 564 |
|
| 565 |
-
# proxy base (unchanged)
|
| 566 |
try:
|
| 567 |
cspec = _get_container_spec()
|
| 568 |
internal, _ = _get_port_and_proto(cspec)
|
|
@@ -574,7 +579,7 @@ def api_wait_instance(pod_id: str = None):
|
|
| 574 |
except Exception:
|
| 575 |
pass
|
| 576 |
|
| 577 |
-
_INST.update({"ip": ip or "", "port": port or ""})
|
| 578 |
_save_state()
|
| 579 |
|
| 580 |
merged = {
|
|
@@ -590,7 +595,6 @@ def api_wait_instance(pod_id: str = None):
|
|
| 590 |
},
|
| 591 |
}
|
| 592 |
return JSONResponse(merged)
|
| 593 |
-
|
| 594 |
# ---------------------------------------------------------------------
|
| 595 |
# Debug: live probes against the instance (IP + Proxy)
|
| 596 |
# ---------------------------------------------------------------------
|
|
|
|
| 376 |
_INST["port"] = _INST.get("port") or ""
|
| 377 |
return JSONResponse(content, r.status_code)
|
| 378 |
# ---------------------------------------------------------------------
|
| 379 |
+
# Poll / read instance status + explicit readiness fields
|
| 380 |
# ---------------------------------------------------------------------
|
| 381 |
@router.get("/api/compute/pods/{pod_id}")
|
| 382 |
def api_get_instance(pod_id: str = None):
|
|
|
|
| 424 |
_log_status(f"PORT_MAPPING declared={declared} chosen={chosen} all={pm}")
|
| 425 |
_log_status(f"RESOLVED_ENDPOINT base={base}")
|
| 426 |
|
| 427 |
+
# --- NEW: health-first readiness (mirror Vertex), fallback to predict existence ---
|
| 428 |
hr = (_INST.get("healthRoute") or "/health").strip()
|
| 429 |
pr = (_INST.get("predictRoute") or "/predict").strip()
|
| 430 |
|
| 431 |
code_h, ms_h, snippet_h = _probe("GET", f"{base}{hr}")
|
| 432 |
_log_status(f"HEALTH_PROBE path={hr} code={code_h} ms={ms_h} body_snippet={snippet_h[:120]}")
|
|
|
|
| 433 |
if code_h in (200, 204):
|
| 434 |
_INST["status"] = "READY"
|
| 435 |
else:
|
|
|
|
| 438 |
if code_p in (200, 204, 400, 405):
|
| 439 |
_INST["status"] = "READY"
|
| 440 |
|
| 441 |
+
# Final prompt URL (prefer IP; else proxy host)
|
| 442 |
+
proute = _INST.get("predictRoute") or "/predict"
|
| 443 |
+
if _INST.get("ip") and _INST.get("port"):
|
| 444 |
prompt_url = f"http://{_INST['ip']}:{_INST['port']}{proute}"
|
| 445 |
+
else:
|
| 446 |
+
proxy_base = f"https://{pid}-{declared}.proxy.runpod.net" if declared else ""
|
| 447 |
+
prompt_url = f"{proxy_base}{proute}" if proxy_base else ""
|
| 448 |
+
if prompt_url:
|
| 449 |
_log_status(f"PROMPT_ENDPOINT {prompt_url}")
|
| 450 |
|
| 451 |
+
# Always include cached readiness data for the UI
|
| 452 |
merged = {**last, "cachedState": {
|
| 453 |
"podId": _INST.get("podId"),
|
| 454 |
"status": _INST.get("status"),
|
|
|
|
| 458 |
"healthRoute": _INST.get("healthRoute"),
|
| 459 |
}}
|
| 460 |
return JSONResponse(merged)
|
|
|
|
| 461 |
# ---------------------------------------------------------------------
|
| 462 |
# Start, Stop, End All — same as before
|
| 463 |
# ---------------------------------------------------------------------
|
|
|
|
| 510 |
return JSONResponse(status_code=500, content={"error": f"RunPod delete failed: {e}"})
|
| 511 |
|
| 512 |
# ---------------------------------------------------------------------
|
| 513 |
+
# Wait instance
|
| 514 |
# ---------------------------------------------------------------------
|
| 515 |
@router.get("/api/compute/wait_instance")
|
| 516 |
def api_wait_instance(pod_id: str = None):
|
|
|
|
| 537 |
pass
|
| 538 |
|
| 539 |
if ip and pm:
|
| 540 |
+
try:
|
| 541 |
+
if isinstance(declared, int) and str(declared) in pm:
|
| 542 |
+
port = str(pm[str(declared)])
|
| 543 |
+
except Exception:
|
| 544 |
+
pass
|
| 545 |
+
if not port and "8080" in pm:
|
| 546 |
port = str(pm["8080"])
|
| 547 |
+
elif not port and pm:
|
| 548 |
port = str(pm[next(iter(pm.keys()))])
|
| 549 |
|
| 550 |
if ip and port:
|
| 551 |
base = f"http://{ip}:{port}"
|
| 552 |
_log_status(f"RESOLVED_IP {base}")
|
| 553 |
|
| 554 |
+
# --- NEW: health-first readiness (mirror Vertex), fallback to predict existence ---
|
| 555 |
hr = (_INST.get("healthRoute") or "/health").strip()
|
| 556 |
pr = (_INST.get("predictRoute") or "/predict").strip()
|
| 557 |
|
| 558 |
code_h, ms_h, snippet_h = _probe("GET", f"{base}{hr}")
|
| 559 |
_log_status(f"HEALTH_PROBE path={hr} code={code_h} ms={ms_h} body_snippet={snippet_h[:120]}")
|
|
|
|
| 560 |
if code_h in (200, 204):
|
| 561 |
_INST["status"] = "READY"
|
| 562 |
else:
|
|
|
|
| 568 |
if _INST.get("predictRoute"):
|
| 569 |
_log_status(f"PROMPT_ENDPOINT {base}{_INST['predictRoute']}")
|
| 570 |
|
|
|
|
| 571 |
try:
|
| 572 |
cspec = _get_container_spec()
|
| 573 |
internal, _ = _get_port_and_proto(cspec)
|
|
|
|
| 579 |
except Exception:
|
| 580 |
pass
|
| 581 |
|
| 582 |
+
_INST.update({"ip": ip or "", "port": port or "", "status": last.get("desiredStatus", "")})
|
| 583 |
_save_state()
|
| 584 |
|
| 585 |
merged = {
|
|
|
|
| 595 |
},
|
| 596 |
}
|
| 597 |
return JSONResponse(merged)
|
|
|
|
| 598 |
# ---------------------------------------------------------------------
|
| 599 |
# Debug: live probes against the instance (IP + Proxy)
|
| 600 |
# ---------------------------------------------------------------------
|