Spaces:
Paused
Paused
CBV01 commited on
Commit Β·
f54c9c8
1
Parent(s): 3b8f5eb
π Added Safe Start mode to prevent startup crashes on Hugging Face
Browse files- backend/main.py +17 -10
backend/main.py
CHANGED
|
@@ -134,17 +134,24 @@ async def lifespan(app: FastAPI):
|
|
| 134 |
print("CORE: Database Schema Initialized.")
|
| 135 |
|
| 136 |
# Cleanup stuck tasks
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
|
|
|
| 144 |
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
|
| 149 |
yield
|
| 150 |
|
|
|
|
| 134 |
print("CORE: Database Schema Initialized.")
|
| 135 |
|
| 136 |
# Cleanup stuck tasks
|
| 137 |
+
try:
|
| 138 |
+
conn = get_db_connection()
|
| 139 |
+
conn.execute("UPDATE tasks SET status = 'pending' WHERE status = 'processing'")
|
| 140 |
+
if hasattr(conn, "commit"): conn.commit()
|
| 141 |
+
if hasattr(conn, "close"): conn.close()
|
| 142 |
+
print("CORE: Stuck tasks reset to pending.")
|
| 143 |
+
except Exception as db_e:
|
| 144 |
+
log_debug(f"CORE_DB_CLEANUP_ERROR: {db_e}")
|
| 145 |
|
| 146 |
+
print("CORE: Starting Task Automation Poller...")
|
| 147 |
+
poller_task = asyncio.create_task(task_poller())
|
| 148 |
+
print("CORE: System Ready and Poller Started.")
|
| 149 |
+
except Exception as e:
|
| 150 |
+
log_debug(f"CRITICAL_STARTUP_ERROR: {e}")
|
| 151 |
+
print(f"CRITICAL_STARTUP_ERROR: {e}")
|
| 152 |
+
# We DO NOT re-raise, so the FastAPI server can still start on port 7860
|
| 153 |
+
# and we can debug it via the UI if needed.
|
| 154 |
+
poller_task = None # type: ignore
|
| 155 |
|
| 156 |
yield
|
| 157 |
|