Mina commited on
Commit ·
87d3243
1
Parent(s): 25ae7fe
Fix: Move DB to /tmp and optimize health checks for HF
Browse files- database.py +5 -1
- main.py +5 -6
database.py
CHANGED
|
@@ -1,7 +1,11 @@
|
|
| 1 |
import aiosqlite
|
| 2 |
import logging
|
| 3 |
|
| 4 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
async def init_db():
|
| 7 |
async with aiosqlite.connect(DB_NAME) as db:
|
|
|
|
| 1 |
import aiosqlite
|
| 2 |
import logging
|
| 3 |
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
# Hugging Face Spaces have a read-only filesystem except for /tmp
|
| 7 |
+
is_hf = os.environ.get("SPACE_ID") is not None or os.environ.get("HF_SPACE") is not None
|
| 8 |
+
DB_NAME = "/tmp/netflix_clone.db" if is_hf else "netflix_clone.db"
|
| 9 |
|
| 10 |
async def init_db():
|
| 11 |
async with aiosqlite.connect(DB_NAME) as db:
|
main.py
CHANGED
|
@@ -93,12 +93,11 @@ app.add_middleware(GZipMiddleware, minimum_size=1000)
|
|
| 93 |
|
| 94 |
@app.get("/")
|
| 95 |
async def root():
|
| 96 |
-
return {
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
}
|
| 102 |
|
| 103 |
@app.get("/latest")
|
| 104 |
async def get_latest(page: int = 1):
|
|
|
|
| 93 |
|
| 94 |
@app.get("/")
|
| 95 |
async def root():
|
| 96 |
+
return {"status": "ok", "message": "MEIH Movies API is running"}
|
| 97 |
+
|
| 98 |
+
@app.get("/health")
|
| 99 |
+
async def health():
|
| 100 |
+
return {"status": "online", "timestamp": time.time()}
|
|
|
|
| 101 |
|
| 102 |
@app.get("/latest")
|
| 103 |
async def get_latest(page: int = 1):
|