新增功能: - 天网协作系统 (HTTP API 端口 6060) - 三种工作流 (查找图片/处理图片/转人工派单) - 图片任务数据库 (支持客户后续增加需求) - 图绘派单系统集成 (API: 8005) - 文字检测与加价 (60-80 元高价值订单) - 风险评估与接单判断 - 作图失败自动转人工 新增文档: - 项目功能汇总.md - 三种工作流功能说明.md - 文字加价功能说明.md - 风险评估功能说明.md - 图片任务数据库功能说明.md - 图绘派单系统集成说明.md - 作图失败转接人工说明.md - DEPLOYMENT.md - TIANWANG_INTEGRATION.md 核心修改: - core/pydantic_ai_agent.py - core/workflow.py - core/websocket_client.py - image/image_analyzer.py - services/service_tuhui_dispatch.py - db/image_tasks_db.py 版本:v1.0 日期:2026-02-28
37 lines
948 B
Python
Executable File
37 lines
948 B
Python
Executable File
# -*- coding: utf-8 -*-
|
|
"""图片队列测试"""
|
|
import sys
|
|
import asyncio
|
|
from pathlib import Path
|
|
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
|
|
|
|
|
async def test_queue_semaphore():
|
|
"""测试队列并发限制"""
|
|
from utils.image_queue import init, run_with_queue, release
|
|
init(max_concurrent=2, max_queue=5)
|
|
running = 0
|
|
max_running = 0
|
|
|
|
async def fake_task():
|
|
nonlocal running, max_running
|
|
running += 1
|
|
max_running = max(max_running, running)
|
|
await asyncio.sleep(0.1)
|
|
running -= 1
|
|
return "ok"
|
|
|
|
results = await asyncio.gather(
|
|
run_with_queue(fake_task()),
|
|
run_with_queue(fake_task()),
|
|
run_with_queue(fake_task()),
|
|
)
|
|
assert all(r == "ok" for r in results)
|
|
assert max_running <= 2
|
|
print("image queue OK")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(test_queue_semaphore())
|
|
print("All image queue tests passed")
|