Spaces:
Running
Running
fix: bound background RAGAS polling
Browse files
api.py
CHANGED
|
@@ -106,7 +106,12 @@ def _with_ragas(job: dict[str, Any]) -> dict[str, Any]:
|
|
| 106 |
else:
|
| 107 |
result["ragas"] = {"status": "unavailable", "error": "RAGAS task was lost during process restart"}
|
| 108 |
elif not task.get("done"):
|
| 109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
elif task.get("error"):
|
| 111 |
result["ragas"] = {"status": "failed", "error": task.get("error")}
|
| 112 |
else:
|
|
|
|
| 106 |
else:
|
| 107 |
result["ragas"] = {"status": "unavailable", "error": "RAGAS task was lost during process restart"}
|
| 108 |
elif not task.get("done"):
|
| 109 |
+
timeout = float(os.getenv("OCR_RAGAS_TIMEOUT_SECONDS", "90"))
|
| 110 |
+
started = float(task.get("started", 0) or 0)
|
| 111 |
+
if started and datetime.now(timezone.utc).timestamp() - started > timeout:
|
| 112 |
+
result["ragas"] = {"status": "failed", "error": f"RAGAS exceeded {int(timeout)} second timeout"}
|
| 113 |
+
else:
|
| 114 |
+
result["ragas"] = {"status": "pending"}
|
| 115 |
elif task.get("error"):
|
| 116 |
result["ragas"] = {"status": "failed", "error": task.get("error")}
|
| 117 |
else:
|