From 60f6ded5ba2a9942c85503f29410d7ea4498b2a4 Mon Sep 17 00:00:00 2001 From: YoungWooSeo Date: Tue, 24 Feb 2026 12:38:36 +0900 Subject: [PATCH] feat: Register db_worker task in main.py lifespan --- backend/app/main.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/backend/app/main.py b/backend/app/main.py index c8b8d43..2c9ee1f 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -18,6 +18,7 @@ import pytz from app.core.config import settings from app.api import api_router from app.services.websocket_manager import websocket_manager +from app.services.db_worker import db_writer_worker from app.core.database import engine, Base, AsyncSessionLocal from app.models import models # 모델 임포트 from app.core.market_schedule import is_market_open @@ -315,6 +316,9 @@ async def lifespan(app: FastAPI): except Exception as e: logger.warning(f"⚠️ 데이트레이딩 포지션 복구 실패 (non-critical): {e}") + # 워커 시작 (스케줄러 및 API 요청 처리 전 큐 준비) + app.state.db_worker_task = asyncio.create_task(db_writer_worker()) + # 스케줄러 시작 app.state.auto_trade_task = asyncio.create_task(auto_trade_scheduler()) app.state.batch_analysis_task = asyncio.create_task(batch_analysis_scheduler()) @@ -324,7 +328,7 @@ async def lifespan(app: FastAPI): # 종료 시 정리 작업 # 스케줄러 중단 - for task_attr in ("auto_trade_task", "batch_analysis_task", "day_trade_task"): + for task_attr in ("auto_trade_task", "batch_analysis_task", "day_trade_task", "db_worker_task"): try: task = getattr(app.state, task_attr, None) if task: