fix: move correlation matrix to background task — prevents startup timeout/OOM
Build and Push / lint-and-test (push) Canceled after 0s
Build and Push / build-services (map[cmd:python -m services.adapters.broker_adapter name:broker-adapter]) (push) Canceled after 0s
Build and Push / build-services (map[cmd:python -m services.aggregation.worker name:aggregation]) (push) Canceled after 0s
Build and Push / build-services (map[cmd:python -m services.extractor.worker name:extractor]) (push) Canceled after 0s
Build and Push / build-services (map[cmd:python -m services.ingestion.worker name:ingestion]) (push) Canceled after 0s
Build and Push / build-services (map[cmd:python -m services.lake_publisher.worker name:lake-publisher]) (push) Canceled after 0s
Build and Push / build-services (map[cmd:python -m services.parser.worker name:parser]) (push) Canceled after 0s
Build and Push / build-services (map[cmd:python -m services.recommendation.worker name:recommendation]) (push) Canceled after 0s
Build and Push / build-services (map[cmd:python -m services.scheduler.app name:scheduler]) (push) Canceled after 0s
Build and Push / build-services (map[cmd:uvicorn services.api.app:app --host 0.0.0.0 --port 8000 name:query-api]) (push) Canceled after 0s
Build and Push / build-services (map[cmd:uvicorn services.risk.app:app --host 0.0.0.0 --port 8000 name:risk]) (push) Canceled after 0s
Build and Push / build-services (map[cmd:uvicorn services.symbol_registry.app:app --host 0.0.0.0 --port 8000 name:symbol-registry]) (push) Canceled after 0s
Build and Push / build-services (map[cmd:uvicorn services.trading.app:app --host 0.0.0.0 --port 8000 name:trading-engine]) (push) Canceled after 0s
Build and Push / build-dashboard (push) Canceled after 0s
Build and Push / build-superset (push) Canceled after 0s
Build and Push / integration-test (push) Canceled after 0s
Build and Push / beta-gate (push) Canceled after 0s

This commit is contained in:
Celes Renata
2026-07-21 15:23:22 +00:00
parent 6bde9d2726
commit 4f021511fa
+11 -2
View File
@@ -159,6 +159,7 @@ class TradingEngine:
asyncio.create_task(self._performance_loop(), name="performance_loop"), asyncio.create_task(self._performance_loop(), name="performance_loop"),
asyncio.create_task(self._risk_tier_scheduler(), name="risk_tier_scheduler"), asyncio.create_task(self._risk_tier_scheduler(), name="risk_tier_scheduler"),
asyncio.create_task(self._rebalance_scheduler(), name="rebalance_scheduler"), asyncio.create_task(self._rebalance_scheduler(), name="rebalance_scheduler"),
asyncio.create_task(self._correlation_startup(), name="correlation_startup"),
] ]
logger.info("Trading engine started with %d worker tasks", len(self._tasks)) logger.info("Trading engine started with %d worker tasks", len(self._tasks))
@@ -598,8 +599,9 @@ class TradingEngine:
initial_capital, invested, available, reserve_balance, open_count, initial_capital, invested, available, reserve_balance, open_count,
) )
# Compute initial correlation matrix from market data # Compute initial correlation matrix from market data (non-blocking)
await self._compute_correlation_matrix() # Launched as a background task in start() to avoid blocking uvicorn startup
self._pending_corr_task = True
async def _decision_loop(self) -> None: async def _decision_loop(self) -> None:
"""Poll recommendations and evaluate them in a continuous loop. """Poll recommendations and evaluate them in a continuous loop.
@@ -1340,6 +1342,13 @@ class TradingEngine:
# Correlation matrix computation # Correlation matrix computation
# ------------------------------------------------------------------ # ------------------------------------------------------------------
async def _correlation_startup(self) -> None:
"""Compute correlation matrix in background so uvicorn can start serving."""
try:
await self._compute_correlation_matrix()
except Exception:
logger.exception("Background correlation matrix computation failed")
async def _compute_correlation_matrix(self) -> None: async def _compute_correlation_matrix(self) -> None:
"""Compute pairwise price correlations from market_snapshots and load into self.correlation_matrix. """Compute pairwise price correlations from market_snapshots and load into self.correlation_matrix.