Spaces:
Sleeping
Sleeping
Chandima Prabhath
commited on
Commit
·
f0052f2
1
Parent(s):
67b571c
Refactor Redis connection handling in config.py and improve startup logging in main.py
Browse files- video_encoder/api/main.py +7 -1
- video_encoder/config.py +2 -6
video_encoder/api/main.py
CHANGED
|
@@ -20,7 +20,13 @@ app = FastAPI(title="Video Encoding Service")
|
|
| 20 |
|
| 21 |
@app.on_event("startup")
|
| 22 |
async def startup_event():
|
| 23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
@app.post("/upload")
|
| 26 |
async def upload_video(file: UploadFile):
|
|
|
|
| 20 |
|
| 21 |
@app.on_event("startup")
|
| 22 |
async def startup_event():
|
| 23 |
+
# Initialize Redis connection on startup
|
| 24 |
+
RedisConfig.get_connection()
|
| 25 |
+
logger.info("Application initialization complete")
|
| 26 |
+
|
| 27 |
+
@app.get("/")
|
| 28 |
+
async def health_check():
|
| 29 |
+
return {"status": "ok"}
|
| 30 |
|
| 31 |
@app.post("/upload")
|
| 32 |
async def upload_video(file: UploadFile):
|
video_encoder/config.py
CHANGED
|
@@ -24,12 +24,8 @@ class RedisConfig:
|
|
| 24 |
@classmethod
|
| 25 |
def get_connection(cls):
|
| 26 |
if not cls.CONN_POOL:
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
logger.info("Successfully connected to Redis")
|
| 30 |
-
except Exception as e:
|
| 31 |
-
logger.error(f"Failed to connect to Redis: {e}")
|
| 32 |
-
raise
|
| 33 |
return cls.CONN_POOL
|
| 34 |
HMAC_SECRET = os.getenv("VIDEO_HMAC_SECRET", "default-secret-change-me")
|
| 35 |
|
|
|
|
| 24 |
@classmethod
|
| 25 |
def get_connection(cls):
|
| 26 |
if not cls.CONN_POOL:
|
| 27 |
+
cls.CONN_POOL = from_url(cls.URL, max_connections=20)
|
| 28 |
+
logger.info("Successfully connected to Redis")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
return cls.CONN_POOL
|
| 30 |
HMAC_SECRET = os.getenv("VIDEO_HMAC_SECRET", "default-secret-change-me")
|
| 31 |
|