CBV01 commited on
Commit
f54c9c8
Β·
1 Parent(s): 3b8f5eb

πŸš€ Added Safe Start mode to prevent startup crashes on Hugging Face

Browse files
Files changed (1) hide show
  1. 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
- conn = get_db_connection()
138
- conn.execute("UPDATE tasks SET status = 'pending' WHERE status = 'processing'")
139
- if hasattr(conn, "commit"): conn.commit()
140
- if hasattr(conn, "close"): conn.close()
141
- print("CORE: Stuck tasks reset to pending.")
142
- except Exception as e:
143
- print(f"CORE: Database Initialization ERROR: {e}")
 
144
 
145
- print("CORE: Starting Task Automation Poller...")
146
- poller_task = asyncio.create_task(task_poller())
147
- print("CORE: System Ready and Poller Started.")
 
 
 
 
 
 
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