修复虎牙任务台卡死与轮询过重,并调整默认端口
默认端口改为后端 8800 / 前端 5174,避免多项目冲突。 清理无执行器的残留 running 任务,支持停止无效批次;绑定二维码结果页不再被假活跃批次锁死。 任务列表默认剥离 base64 小程序码,按需拉取详情,空闲轮询降频,显著降低 tasks 请求体积。
This commit is contained in:
+16
-2
@@ -25,6 +25,19 @@ async def lifespan(app: FastAPI):
|
||||
setup_logger(level=_log_level, log_dir=str(_log_dir))
|
||||
|
||||
init_db()
|
||||
# 进程重启后内存批次丢失,清理历史 pending/running,避免前端被假活跃批次锁死。
|
||||
from loguru import logger
|
||||
|
||||
from .database import SessionLocal
|
||||
from .services.huya_service import cleanup_orphan_huya_tasks
|
||||
|
||||
db = SessionLocal()
|
||||
try:
|
||||
cleaned = cleanup_orphan_huya_tasks(db, message="任务已中断(服务重启)")
|
||||
if cleaned:
|
||||
logger.info(f"启动清理虎牙残留任务: {cleaned} 条")
|
||||
finally:
|
||||
db.close()
|
||||
yield
|
||||
|
||||
|
||||
@@ -39,7 +52,7 @@ _cors_env = os.getenv("CORS_ORIGINS", "")
|
||||
if _cors_env:
|
||||
_cors_origins = [o.strip() for o in _cors_env.split(",") if o.strip()]
|
||||
else:
|
||||
_cors_origins = ["http://localhost:5173", "http://localhost:3000"]
|
||||
_cors_origins = ["http://localhost:5174", "http://localhost:5173", "http://localhost:3000"]
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
@@ -115,7 +128,8 @@ if _INDEX_HTML.exists():
|
||||
|
||||
def run():
|
||||
_reload = os.getenv("UVICORN_RELOAD", "false").lower() == "true"
|
||||
uvicorn.run("web.backend.main:app", host="0.0.0.0", port=8000, reload=_reload)
|
||||
_port = int(os.getenv("BACKEND_PORT", "8800"))
|
||||
uvicorn.run("web.backend.main:app", host="0.0.0.0", port=_port, reload=_reload)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user