anderson-ufrj
commited on
Commit
·
316a293
1
Parent(s):
584cac1
feat(database): allow app to run without database connection for HuggingFace Spaces
Browse files- Modified init_database() to catch and log errors without raising
- Updated get_db_session() to yield None when no database is available
- Added warning logs when running without database
- Enables deployment on HuggingFace Spaces which doesn't provide PostgreSQL
src/db/session.py
CHANGED
|
@@ -28,7 +28,7 @@ async def get_session(
|
|
| 28 |
read_only: Use read replica if available
|
| 29 |
|
| 30 |
Yields:
|
| 31 |
-
AsyncSession instance
|
| 32 |
"""
|
| 33 |
async with connection_pool_service.get_db_session(
|
| 34 |
pool_name="main",
|
|
@@ -52,7 +52,9 @@ async def init_database():
|
|
| 52 |
error=str(e),
|
| 53 |
exc_info=True
|
| 54 |
)
|
| 55 |
-
raise
|
|
|
|
|
|
|
| 56 |
|
| 57 |
|
| 58 |
async def close_database():
|
|
|
|
| 28 |
read_only: Use read replica if available
|
| 29 |
|
| 30 |
Yields:
|
| 31 |
+
AsyncSession instance or None if no database available
|
| 32 |
"""
|
| 33 |
async with connection_pool_service.get_db_session(
|
| 34 |
pool_name="main",
|
|
|
|
| 52 |
error=str(e),
|
| 53 |
exc_info=True
|
| 54 |
)
|
| 55 |
+
# Don't raise - allow app to start without database
|
| 56 |
+
# This is needed for HuggingFace Spaces deployment
|
| 57 |
+
logger.warning("Running without database connection - some features may be limited")
|
| 58 |
|
| 59 |
|
| 60 |
async def close_database():
|
src/services/connection_pool_service.py
CHANGED
|
@@ -289,7 +289,10 @@ class ConnectionPoolService:
|
|
| 289 |
|
| 290 |
engine = self._engines.get(pool_name)
|
| 291 |
if not engine:
|
| 292 |
-
|
|
|
|
|
|
|
|
|
|
| 293 |
|
| 294 |
# Track wait time
|
| 295 |
start_time = time.time()
|
|
|
|
| 289 |
|
| 290 |
engine = self._engines.get(pool_name)
|
| 291 |
if not engine:
|
| 292 |
+
# No database available - return None
|
| 293 |
+
logger.warning(f"Database pool '{pool_name}' not found - running without database")
|
| 294 |
+
yield None
|
| 295 |
+
return
|
| 296 |
|
| 297 |
# Track wait time
|
| 298 |
start_time = time.time()
|