— Add waiting tasks count on index page and app API

This commit is contained in:
Luc Didry 2025-04-14 11:50:56 +02:00
parent 876ac3cf54
commit 4c378e94ac
No known key found for this signature in database
GPG key ID: EA868E12D0257E3C
5 changed files with 29 additions and 1 deletions

View file

@ -7,10 +7,11 @@
- 🔊 — Improve check agent log
- 🔒️ — Logging out now invalidate tokens
- 📝 — Improve OpenAPI doc
- 🤕 — Fix order of tasks sent to agent
- 🩹 — Fix order of tasks sent to agent
- ✨ — Add application API (fix #86)
- ⚡️ — Faster websites configuration reloading (#85)
- 💄 — Better mobile display
- ✨ — Add waiting tasks count on index page and app API
## 0.9.0

View file

@ -594,6 +594,19 @@ async def get_severity_counts(db: Session) -> dict:
return counts_dict
async def get_waiting_tasks_count(db: Session) -> int:
"""Get the count of tasks waiting to be processed"""
waiting_tasks = (
db.query(Task.id)
.filter(
Task.selected_by == None,
((Task.next_run <= datetime.now()) | (Task.next_run == None)),
)
.count()
)
return waiting_tasks
async def reschedule_all(db: Session):
"""Reschedule checks of all non OK tasks ASAP"""
db.query(Task).filter(Task.severity != "ok").update(

View file

@ -170,6 +170,7 @@ async def logout(
class SeverityCounts(BaseModel):
severities: Dict[Literal["ok", "warning", "critical", "unknown"], int]
agents: int
waiting_tasks: int
model_config = {
"json_schema_extra": {
@ -177,6 +178,7 @@ class SeverityCounts(BaseModel):
{
"severities": {"ok": 10, "warning": 0, "critical": 2, "unknown": 0},
"agents": 1,
"waiting_tasks": 3,
}
]
}
@ -194,9 +196,12 @@ async def get_severity_counts(
agents = db.query(Result.agent_id).distinct().all()
waiting_tasks = await queries.get_waiting_tasks_count(db)
return {
"severities": counts_dict,
"agents": len(agents),
"waiting_tasks": waiting_tasks,
}

View file

@ -158,12 +158,15 @@ async def get_severity_counts_view(
agents = db.query(Result.agent_id).distinct().all()
waiting_tasks = await queries.get_waiting_tasks_count(db)
return templates.TemplateResponse(
"index.html",
{
"request": request,
"counts_dict": counts_dict,
"agents": agents,
"waiting_tasks": waiting_tasks,
"auto_refresh_enabled": auto_refresh_enabled,
"auto_refresh_seconds": auto_refresh_seconds,
"user": user,

View file

@ -11,6 +11,9 @@
{{ agents | length }} agent{{ 's' if agents | length > 1 }}
</a>
</li>
<li>
{{ waiting_tasks }} task{{ 's' if waiting_tasks > 1 }} awaiting to be processed
</li>
</ul>
<ul>
<li>
@ -51,6 +54,9 @@
{{ agents | length }} agent{{ 's' if agents | length > 1 }}
</a>
</li>
<li>
{{ waiting_tasks }} task{{ 's' if waiting_tasks > 1 }} awaiting to be processed
</li>
</ul>
<div>
<ul>