Spaces:
Running
Running
Commit
·
ff310f2
1
Parent(s):
eb27b67
Deploy Signal Generator app
Browse files- src/main.py +24 -0
src/main.py
CHANGED
|
@@ -210,6 +210,30 @@ from fastapi import Request
|
|
| 210 |
# Setup templates
|
| 211 |
templates = Jinja2Templates(directory="src/templates")
|
| 212 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 213 |
@app.get("/api/signals")
|
| 214 |
async def get_signals():
|
| 215 |
"""Get recent signals (Public Read-Only)"""
|
|
|
|
| 210 |
# Setup templates
|
| 211 |
templates = Jinja2Templates(directory="src/templates")
|
| 212 |
|
| 213 |
+
# --- Coordinator Startup ---
|
| 214 |
+
@app.on_event("startup")
|
| 215 |
+
async def startup_event():
|
| 216 |
+
"""Start the Coordinator (News Scraper + Scheduler) in background"""
|
| 217 |
+
import threading
|
| 218 |
+
import sys
|
| 219 |
+
from pathlib import Path
|
| 220 |
+
|
| 221 |
+
# Ensure src is in path for coordinator imports
|
| 222 |
+
try:
|
| 223 |
+
from src.orchestrator.coordinator import Coordinator
|
| 224 |
+
logger.info("Initializing Coordinator...")
|
| 225 |
+
|
| 226 |
+
coordinator = Coordinator()
|
| 227 |
+
# Start coordinator in a separate thread because it blocks
|
| 228 |
+
coord_thread = threading.Thread(target=coordinator.start, daemon=True)
|
| 229 |
+
coord_thread.start()
|
| 230 |
+
logger.info("✅ Coordinator started in background thread")
|
| 231 |
+
|
| 232 |
+
except Exception as e:
|
| 233 |
+
logger.error(f"❌ Failed to start Coordinator: {e}")
|
| 234 |
+
|
| 235 |
+
# ... existing code ...
|
| 236 |
+
|
| 237 |
@app.get("/api/signals")
|
| 238 |
async def get_signals():
|
| 239 |
"""Get recent signals (Public Read-Only)"""
|