新增获取任务接口
This commit is contained in:
parent
3df782999b
commit
d08b4e203b
17
main.py
17
main.py
|
|
@ -38,18 +38,18 @@ def get_account_manager():
|
|||
return None
|
||||
|
||||
|
||||
def get_task_manager():
|
||||
def get_crawler_manager():
|
||||
"""任务管理器实例"""
|
||||
config = get_config()
|
||||
try:
|
||||
from crawler_management.crawler_management import CrawlerManagement
|
||||
return AllTask(config)
|
||||
return CrawlerManagement(config)
|
||||
except ImportError:
|
||||
print(f"未找到AllTask类,返回模拟实例")
|
||||
return None
|
||||
|
||||
|
||||
def get_crawler_manager():
|
||||
def get_task_manager():
|
||||
"""任务获取管理器实例"""
|
||||
config = get_config()
|
||||
try:
|
||||
|
|
@ -133,13 +133,22 @@ async def update_account(account_data: AccountUpdate, account_manager: Any = Dep
|
|||
raise HTTPException(status_code=500, detail="账号失败,请重试,失败原因:{}".format(e))
|
||||
|
||||
|
||||
@app.get("/get_crawler_task", summary="获取任务")
|
||||
@app.post("/get_crawler_task", summary="获取任务")
|
||||
async def get_crawler_task(task_data: CrawlerItem, task_manager: Any = Depends(get_crawler_manager)):
|
||||
"""
|
||||
获取指定应用的可用账号
|
||||
- **app_name**: 应用名称
|
||||
- **country**: 应用名称
|
||||
"""
|
||||
try:
|
||||
params = task_data.model_dump()
|
||||
result = task_manager.get_task_item(params)
|
||||
if result:
|
||||
return {"code": 200, "message": "任务获取成功", "data": result}
|
||||
raise HTTPException(status_code=404, detail="队列暂时没有任务,请等待一段时间后重新尝试")
|
||||
except Exception as e:
|
||||
print(f"获取任务失败,失败原因: {e}")
|
||||
raise HTTPException(status_code=500, detail="获取任务失败;失败原因{}".format(e))
|
||||
|
||||
|
||||
@app.post("/receive_data", summary="接收抓取得数据")
|
||||
|
|
|
|||
Loading…
Reference in New Issue