初始化

This commit is contained in:
2026-09-03 14:31:25 +08:00
parent 30dd0bea14
commit 64a51f2567
23 changed files with 2091 additions and 144 deletions

0
api/__init__.py Normal file
View File

23
api/lottery_api.py Normal file
View File

@@ -0,0 +1,23 @@
from fastapi import APIRouter
from pydantic import BaseModel, ConfigDict
from core.db import SessionDep
from core.dto.api_response import ApiResponse
# 彩票相关的路由
lottery_router = APIRouter(prefix="/lottery", tags=["lottery"])
class DltQuery(BaseModel):
""" 接口入参 """
page: int
page_size: int
model_config = ConfigDict(
extra="forbid", # forbid:禁止多余字段; ignore:忽略; allow:允许
frozen=False, # frozen=True 对象不可修改(冻结)
)
# 大乐透相关的
@lottery_router.get("/dlt")
async def get_list(db: SessionDep,page: int, page_size: int) -> ApiResponse:
# db.get()
return ApiResponse(code=200, message="成功")

80
api/scheduler_api.py Normal file
View File

@@ -0,0 +1,80 @@
from fastapi import APIRouter, HTTPException
from typing import Any, Dict
from core.db import SessionDep
from core.dto.api_response import ApiResponse
from core.task.dlt_scheduler import scheduler
# 彩票相关的路由
scheduler_router = APIRouter(prefix="/scheduler", tags=["大乐透调度器管理"])
@scheduler_router.get("/status")
async def get_scheduler_status() -> Dict[str, Any]:
"""获取调度器状态"""
lists = []
for job in scheduler.get_jobs():
lists.append({
"id": job.id,
"name": job.name,
"next_run_time": job.next_run_time
})
return {
"running": scheduler.scheduler.running,
"jobs": lists
}
@scheduler_router.post("/run")
async def run_job_now() -> Dict[str, Any]:
"""立即执行定时任务"""
try:
success, message = await scheduler.run_job_now()
return {
"success": success,
"message": message
}
except Exception as e:
raise HTTPException(status_code=500, detail=str(e))
@scheduler_router.post("/pause")
async def pause_scheduler() -> Dict[str, Any]:
"""暂停调度器"""
if scheduler.pause():
return {
"success": True,
"message": "调度器已停止"
}
return {
"success": False,
"message": "调度器停止失败"
}
@scheduler_router.post("/resume")
async def resume_scheduler() -> Dict[str, Any]:
"""暂停调度器"""
if scheduler.resume():
return {
"success": True,
"message": "调度器已恢复运行"
}
return {
"success": False,
"message": "调度器恢复运行失败"
}
@scheduler_router.get("/jobs")
async def list_jobs() -> Dict[str, Any]:
"""列出所有定时任务"""
lists = []
for job in scheduler.get_jobs():
lists.append({
"id": job.id,
"name": job.name,
"next_run_time": job.next_run_time
})
return {
"jobs": lists
}