first commit
This commit is contained in:
0
api/__init__.py
Normal file
0
api/__init__.py
Normal file
BIN
api/__pycache__/__init__.cpython-313.pyc
Normal file
BIN
api/__pycache__/__init__.cpython-313.pyc
Normal file
Binary file not shown.
BIN
api/__pycache__/trigger.cpython-313.pyc
Normal file
BIN
api/__pycache__/trigger.cpython-313.pyc
Normal file
Binary file not shown.
48
api/trigger.py
Normal file
48
api/trigger.py
Normal file
@@ -0,0 +1,48 @@
|
||||
from fastapi import APIRouter, BackgroundTasks, HTTPException
|
||||
from wechat_auto.models.activity import ActivityModel, TaskStatus
|
||||
from wechat_auto.core.task_scheduler import task_scheduler
|
||||
from wechat_auto.utils.logger import logger
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@router.post("/api/publish", response_model=dict)
|
||||
async def publish_activity(activity: ActivityModel, background_tasks: BackgroundTasks):
|
||||
logger.info(f"收到发布活动请求: {activity.title}")
|
||||
|
||||
result = await task_scheduler.publish_activity(activity)
|
||||
|
||||
return {
|
||||
"code": 200 if result["status"] == "success" else 500,
|
||||
"message": "任务已提交" if result["status"] == "success" else "任务失败",
|
||||
"data": result
|
||||
}
|
||||
|
||||
|
||||
@router.get("/api/task/{task_id}", response_model=dict)
|
||||
async def get_task_status(task_id: str):
|
||||
task = task_scheduler.get_task_status(task_id)
|
||||
if not task:
|
||||
raise HTTPException(status_code=404, detail="任务不存在")
|
||||
|
||||
return {
|
||||
"code": 200,
|
||||
"data": task
|
||||
}
|
||||
|
||||
|
||||
@router.get("/api/tasks", response_model=dict)
|
||||
async def list_tasks():
|
||||
tasks = task_scheduler.list_tasks()
|
||||
return {
|
||||
"code": 200,
|
||||
"data": tasks
|
||||
}
|
||||
|
||||
|
||||
@router.get("/api/health")
|
||||
async def health_check():
|
||||
return {
|
||||
"status": "ok",
|
||||
"service": "wechat_auto"
|
||||
}
|
||||
Reference in New Issue
Block a user