update
This commit is contained in:
parent
f9d09fefca
commit
e4f5527f64
@ -17,6 +17,7 @@ import os
|
||||
_price_monitor_task = None
|
||||
_report_task = None
|
||||
_stock_agent_task = None
|
||||
_crypto_agent_task = None
|
||||
|
||||
|
||||
async def price_monitor_loop():
|
||||
@ -148,7 +149,7 @@ async def periodic_report_loop():
|
||||
@asynccontextmanager
|
||||
async def lifespan(app: FastAPI):
|
||||
"""应用生命周期管理"""
|
||||
global _price_monitor_task, _report_task, _stock_agent_task
|
||||
global _price_monitor_task, _report_task, _stock_agent_task, _crypto_agent_task
|
||||
|
||||
# 启动时执行
|
||||
logger.info("应用启动")
|
||||
@ -162,6 +163,15 @@ async def lifespan(app: FastAPI):
|
||||
_report_task = asyncio.create_task(periodic_report_loop())
|
||||
logger.info("定时报告任务已创建")
|
||||
|
||||
# 启动加密货币智能体
|
||||
if getattr(settings, 'crypto_symbols', '') and settings.crypto_symbols.strip():
|
||||
try:
|
||||
from app.crypto_agent.crypto_agent import crypto_agent
|
||||
_crypto_agent_task = asyncio.create_task(crypto_agent.run())
|
||||
logger.info(f"加密货币智能体已启动,监控: {settings.crypto_symbols}")
|
||||
except Exception as e:
|
||||
logger.error(f"加密货币智能体启动失败: {e}")
|
||||
|
||||
# 启动美股智能体
|
||||
if getattr(settings, 'stock_symbols', '') and settings.stock_symbols.strip():
|
||||
try:
|
||||
@ -194,6 +204,15 @@ async def lifespan(app: FastAPI):
|
||||
pass
|
||||
logger.info("定时报告任务已停止")
|
||||
|
||||
# 停止加密货币智能体
|
||||
if _crypto_agent_task:
|
||||
_crypto_agent_task.cancel()
|
||||
try:
|
||||
await _crypto_agent_task
|
||||
except asyncio.CancelledError:
|
||||
pass
|
||||
logger.info("加密货币智能体已停止")
|
||||
|
||||
# 停止美股智能体
|
||||
if _stock_agent_task:
|
||||
_stock_agent_task.cancel()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user