- 新增 platform_scheduled_tasks, platform_task_logs, platform_script_vars, platform_secrets 数据库表 - 实现 ScriptSDK 提供 AI/通知/DB/HTTP/变量存储/参数获取等功能 - 实现安全的脚本执行器,支持沙箱环境和禁止危险操作 - 实现 APScheduler 调度服务,支持简单时间点和 CRON 表达式 - 新增定时任务 API 路由,包含 CRUD、执行、日志、密钥管理 - 新增定时任务前端页面,支持脚本编辑、测试运行、日志查看
This commit is contained in:
@@ -14,12 +14,10 @@ from .routers.wechat import router as wechat_router
|
||||
from .routers.alerts import router as alerts_router
|
||||
from .routers.cost import router as cost_router
|
||||
from .routers.quota import router as quota_router
|
||||
from .routers.tool_configs import router as tool_configs_router
|
||||
from .routers.tasks import router as tasks_router
|
||||
from .routers.scripts import router as scripts_router
|
||||
from .middleware import TraceMiddleware, setup_exception_handlers, RequestLoggerMiddleware
|
||||
from .middleware.trace import setup_logging
|
||||
from .services.scheduler import start_scheduler, shutdown_scheduler
|
||||
from .services.scheduler import scheduler_service
|
||||
|
||||
# 配置日志(包含 TraceID)
|
||||
setup_logging(level=logging.INFO, include_trace=True)
|
||||
@@ -70,29 +68,20 @@ app.include_router(wechat_router, prefix="/api")
|
||||
app.include_router(alerts_router, prefix="/api")
|
||||
app.include_router(cost_router, prefix="/api")
|
||||
app.include_router(quota_router, prefix="/api")
|
||||
app.include_router(tool_configs_router, prefix="/api")
|
||||
app.include_router(tasks_router, prefix="/api")
|
||||
app.include_router(scripts_router, prefix="/api")
|
||||
app.include_router(tasks_router)
|
||||
|
||||
|
||||
# 应用生命周期事件
|
||||
@app.on_event("startup")
|
||||
async def startup_event():
|
||||
"""应用启动时初始化调度器"""
|
||||
try:
|
||||
start_scheduler()
|
||||
logging.info("Scheduler started successfully")
|
||||
except Exception as e:
|
||||
logging.error(f"Failed to start scheduler: {e}")
|
||||
"""应用启动时启动调度器"""
|
||||
scheduler_service.start()
|
||||
|
||||
|
||||
@app.on_event("shutdown")
|
||||
async def shutdown_event():
|
||||
"""应用关闭时停止调度器"""
|
||||
try:
|
||||
shutdown_scheduler()
|
||||
logging.info("Scheduler shutdown successfully")
|
||||
except Exception as e:
|
||||
logging.error(f"Failed to shutdown scheduler: {e}")
|
||||
"""应用关闭时关闭调度器"""
|
||||
scheduler_service.shutdown()
|
||||
|
||||
|
||||
@app.get("/")
|
||||
|
||||
Reference in New Issue
Block a user