Spaces:
Sleeping
Sleeping
Commit Β·
af4749f
1
Parent(s): d8722a7
Add comprehensive DEBUG traces to startup process for HF troubleshooting
Browse files- backend/app.py +28 -2
backend/app.py
CHANGED
|
@@ -67,35 +67,61 @@ app.include_router(observability.router)
|
|
| 67 |
@app.on_event("startup")
|
| 68 |
async def startup_event():
|
| 69 |
"""Start background services on app startup"""
|
|
|
|
| 70 |
logger.info("β
Backend server starting...")
|
| 71 |
|
| 72 |
# π§ Create necessary directories
|
|
|
|
| 73 |
ensure_directories()
|
| 74 |
logger.info("π Directory structure created")
|
|
|
|
| 75 |
|
| 76 |
# ποΈ Initialize database on startup
|
|
|
|
| 77 |
try:
|
| 78 |
from backend.database.init_db import init_database
|
| 79 |
from backend.database import init_db, test_database_connection, add_sample_data_for_hf
|
| 80 |
|
|
|
|
|
|
|
|
|
|
| 81 |
init_database(reset=False, force=False)
|
|
|
|
|
|
|
|
|
|
| 82 |
init_db() # Create tables using SQLAlchemy
|
|
|
|
| 83 |
|
| 84 |
# Show database type info
|
| 85 |
-
|
|
|
|
|
|
|
|
|
|
| 86 |
logger.info("π HF Spaces: Using in-memory database for user privacy")
|
| 87 |
logger.info("π Note: Data will be cleared when container restarts")
|
|
|
|
| 88 |
|
| 89 |
# Test database connection first
|
| 90 |
logger.info("π Testing database connection...")
|
|
|
|
| 91 |
|
| 92 |
# Add sample data for HF Spaces
|
| 93 |
logger.info("π Loading sample data for demonstration...")
|
| 94 |
-
add_sample_data_for_hf()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
else:
|
| 96 |
logger.info("πΎ Local development: Using persistent database")
|
|
|
|
| 97 |
|
| 98 |
logger.info("ποΈ Database initialized successfully")
|
|
|
|
| 99 |
except Exception as e:
|
| 100 |
logger.error(f"β Database initialization failed: {e}")
|
| 101 |
import traceback
|
|
|
|
| 67 |
@app.on_event("startup")
|
| 68 |
async def startup_event():
|
| 69 |
"""Start background services on app startup"""
|
| 70 |
+
print("π¨ DEBUG: startup_event() called")
|
| 71 |
logger.info("β
Backend server starting...")
|
| 72 |
|
| 73 |
# π§ Create necessary directories
|
| 74 |
+
print("π¨ DEBUG: About to ensure directories")
|
| 75 |
ensure_directories()
|
| 76 |
logger.info("π Directory structure created")
|
| 77 |
+
print("π¨ DEBUG: Directory structure created")
|
| 78 |
|
| 79 |
# ποΈ Initialize database on startup
|
| 80 |
+
print("π¨ DEBUG: About to initialize database")
|
| 81 |
try:
|
| 82 |
from backend.database.init_db import init_database
|
| 83 |
from backend.database import init_db, test_database_connection, add_sample_data_for_hf
|
| 84 |
|
| 85 |
+
print("π¨ DEBUG: Imported database functions")
|
| 86 |
+
|
| 87 |
+
print("π¨ DEBUG: Calling init_database")
|
| 88 |
init_database(reset=False, force=False)
|
| 89 |
+
print("π¨ DEBUG: init_database completed")
|
| 90 |
+
|
| 91 |
+
print("π¨ DEBUG: Calling init_db")
|
| 92 |
init_db() # Create tables using SQLAlchemy
|
| 93 |
+
print("π¨ DEBUG: init_db completed")
|
| 94 |
|
| 95 |
# Show database type info
|
| 96 |
+
space_id = os.getenv("SPACE_ID")
|
| 97 |
+
print(f"π¨ DEBUG: SPACE_ID = {space_id}")
|
| 98 |
+
|
| 99 |
+
if space_id:
|
| 100 |
logger.info("π HF Spaces: Using in-memory database for user privacy")
|
| 101 |
logger.info("π Note: Data will be cleared when container restarts")
|
| 102 |
+
print("π¨ DEBUG: Detected HF Spaces environment")
|
| 103 |
|
| 104 |
# Test database connection first
|
| 105 |
logger.info("π Testing database connection...")
|
| 106 |
+
print("π¨ DEBUG: About to test database connection")
|
| 107 |
|
| 108 |
# Add sample data for HF Spaces
|
| 109 |
logger.info("π Loading sample data for demonstration...")
|
| 110 |
+
print("π¨ DEBUG: About to call add_sample_data_for_hf()")
|
| 111 |
+
try:
|
| 112 |
+
add_sample_data_for_hf()
|
| 113 |
+
print("π¨ DEBUG: add_sample_data_for_hf() completed without error")
|
| 114 |
+
except Exception as e:
|
| 115 |
+
print(f"π¨ DEBUG: add_sample_data_for_hf() failed with error: {e}")
|
| 116 |
+
import traceback
|
| 117 |
+
print("π¨ DEBUG: Full traceback:")
|
| 118 |
+
traceback.print_exc()
|
| 119 |
else:
|
| 120 |
logger.info("πΎ Local development: Using persistent database")
|
| 121 |
+
print("π¨ DEBUG: Detected local development environment")
|
| 122 |
|
| 123 |
logger.info("ποΈ Database initialized successfully")
|
| 124 |
+
print("π¨ DEBUG: Database initialization completed")
|
| 125 |
except Exception as e:
|
| 126 |
logger.error(f"β Database initialization failed: {e}")
|
| 127 |
import traceback
|