Files
planManage/app/services/queue_service.py
T

18 lines
501 B
Python
Raw Normal View History

"""任务队列辅助服务"""
from __future__ import annotations
from app import database as db
async def get_queue_stats() -> dict:
"""队列统计"""
d = await db.get_db()
stats = {}
for status in ("pending", "running", "completed", "failed", "cancelled"):
cur = await d.execute("SELECT COUNT(*) as cnt FROM tasks WHERE status=?", (status,))
row = await cur.fetchone()
stats[status] = row["cnt"]
stats["total"] = sum(stats.values())
return stats