diff --git a/backend/main.py b/backend/main.py index 65bb580..8364f7d 100644 --- a/backend/main.py +++ b/backend/main.py @@ -41,7 +41,11 @@ from routers.submissions import router as submissions_router from routers.costs import router as costs_router from routers.dashboard import router as dashboard_router from routers.roles import router as roles_router -from routers.reports import router as reports_router +try: + from routers.reports import router as reports_router +except ImportError as e: + reports_router = None + logging.warning(f"[路由] reports 模块加载失败: {e}") app.include_router(auth_router) app.include_router(users_router) @@ -50,7 +54,8 @@ app.include_router(submissions_router) app.include_router(costs_router) app.include_router(dashboard_router) app.include_router(roles_router) -app.include_router(reports_router) +if reports_router: + app.include_router(reports_router) # 前端静态文件 frontend_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)), "frontend", "dist") @@ -68,16 +73,22 @@ if os.path.exists(frontend_dir): @app.on_event("startup") async def start_scheduler(): """启动定时任务调度器""" - from services.scheduler_service import setup_scheduler - setup_scheduler() + try: + from services.scheduler_service import setup_scheduler + setup_scheduler() + except Exception as e: + logger.warning(f"[定时任务] 启动失败(不影响核心功能): {e}") @app.on_event("shutdown") async def stop_scheduler(): """关闭定时任务调度器""" - from services.scheduler_service import scheduler - scheduler.shutdown(wait=False) - logger.info("[定时任务] 已关闭") + try: + from services.scheduler_service import scheduler + scheduler.shutdown(wait=False) + logger.info("[定时任务] 已关闭") + except Exception: + pass @app.on_event("startup")