feat(signal_v2-phase3b): main.py lifespan loads ChronosPredictor
AppContext.chronos field. lifespan: if KIS_APP_KEY set, load ChronosPredictor(model_name=settings.chronos_model). Exceptions during load logged + signal_v2 continues without chronos (other endpoints unaffected). poll_loop receives chronos param. 45 tests pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,7 @@ from contextlib import asynccontextmanager
|
||||
from fastapi import FastAPI
|
||||
|
||||
from signal_v2 import state as state_mod
|
||||
from signal_v2.chronos_predictor import ChronosPredictor
|
||||
from signal_v2.config import get_settings
|
||||
from signal_v2.kis_client import KISClient
|
||||
from signal_v2.kis_websocket import KISWebSocket
|
||||
@@ -24,6 +25,7 @@ class AppContext:
|
||||
poll_task: asyncio.Task | None = None
|
||||
kis_client: KISClient | None = None
|
||||
kis_ws: KISWebSocket | None = None
|
||||
chronos: ChronosPredictor | None = None
|
||||
|
||||
|
||||
_ctx = AppContext()
|
||||
@@ -69,10 +71,17 @@ async def lifespan(app: FastAPI):
|
||||
except Exception:
|
||||
logger.exception("KIS WebSocket startup failed — continuing without realtime asking_price")
|
||||
|
||||
# Load Chronos (heavy: ~1GB model download first time)
|
||||
try:
|
||||
_ctx.chronos = ChronosPredictor(model_name=settings.chronos_model)
|
||||
except Exception:
|
||||
logger.exception("ChronosPredictor load failed — continuing without chronos predictions")
|
||||
|
||||
_ctx.poll_task = asyncio.create_task(
|
||||
poll_loop(
|
||||
_ctx.client, state_mod.state, _ctx.shutdown,
|
||||
kis_client=_ctx.kis_client,
|
||||
chronos=_ctx.chronos,
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user