Spaces:
Running
on
T4
Running
on
T4
Update app.py
Browse files
app.py
CHANGED
|
@@ -236,62 +236,62 @@ def download_from_spaces(key):
|
|
| 236 |
def root():
|
| 237 |
return RedirectResponse("/gradio")
|
| 238 |
|
| 239 |
-
# @fastapi_app.get("/health")
|
| 240 |
-
# async def health():
|
| 241 |
-
# return {"status": "healthy
|
| 242 |
@fastapi_app.get("/health")
|
| 243 |
async def health():
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
| 260 |
-
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
|
|
|
|
|
|
|
|
|
| 295 |
|
| 296 |
from fastapi import Form
|
| 297 |
import requests
|
|
|
|
| 236 |
def root():
|
| 237 |
return RedirectResponse("/gradio")
|
| 238 |
|
|
|
|
|
|
|
|
|
|
| 239 |
@fastapi_app.get("/health")
|
| 240 |
async def health():
|
| 241 |
+
return {"status": "healthy"}
|
| 242 |
+
# @fastapi_app.get("/health")
|
| 243 |
+
# async def health():
|
| 244 |
+
# mongo_ok = False
|
| 245 |
+
# spaces_ok = False
|
| 246 |
+
# mongo_error = None
|
| 247 |
+
# spaces_error = None
|
| 248 |
+
|
| 249 |
+
# # ---- MongoDB Check (ASYNC SAFE) ----
|
| 250 |
+
# try:
|
| 251 |
+
# if database is None:
|
| 252 |
+
# raise Exception("MongoDB client not initialized")
|
| 253 |
+
|
| 254 |
+
# await database.command("ping")
|
| 255 |
+
# mongo_ok = True
|
| 256 |
+
|
| 257 |
+
# except Exception as e:
|
| 258 |
+
# mongo_error = str(e)
|
| 259 |
+
|
| 260 |
+
# # ---- DigitalOcean Spaces Check (RUN IN THREADPOOL) ----
|
| 261 |
+
# try:
|
| 262 |
+
# def check_spaces():
|
| 263 |
+
# client = get_spaces_client()
|
| 264 |
+
# client.list_objects_v2(
|
| 265 |
+
# Bucket=DO_SPACES_BUCKET,
|
| 266 |
+
# MaxKeys=1
|
| 267 |
+
# )
|
| 268 |
+
|
| 269 |
+
# await run_in_threadpool(check_spaces)
|
| 270 |
+
# spaces_ok = True
|
| 271 |
+
|
| 272 |
+
# except Exception as e:
|
| 273 |
+
# spaces_error = str(e)
|
| 274 |
+
|
| 275 |
+
# # ---- FINAL RESPONSE ----
|
| 276 |
+
# if mongo_ok and spaces_ok:
|
| 277 |
+
# return {
|
| 278 |
+
# "status": "healthy",
|
| 279 |
+
# "mongo": "connected",
|
| 280 |
+
# "spaces": "connected",
|
| 281 |
+
# "timestamp": datetime.utcnow().isoformat()
|
| 282 |
+
# }
|
| 283 |
+
|
| 284 |
+
# raise HTTPException(
|
| 285 |
+
# status_code=503,
|
| 286 |
+
# detail={
|
| 287 |
+
# "status": "unhealthy",
|
| 288 |
+
# "mongo": "connected" if mongo_ok else "failed",
|
| 289 |
+
# "spaces": "connected" if spaces_ok else "failed",
|
| 290 |
+
# "mongo_error": mongo_error,
|
| 291 |
+
# "spaces_error": spaces_error,
|
| 292 |
+
# "timestamp": datetime.utcnow().isoformat()
|
| 293 |
+
# }
|
| 294 |
+
# )
|
| 295 |
|
| 296 |
from fastapi import Form
|
| 297 |
import requests
|