diff --git a/CHANGELOG.md b/CHANGELOG.md index b476b01..fae9faa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/argos/server/queries.py b/argos/server/queries.py index cdf80fe..940ed35 100644 --- a/argos/server/queries.py +++ b/argos/server/queries.py @@ -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( diff --git a/argos/server/routes/api_app.py b/argos/server/routes/api_app.py index 487caf3..1c60079 100644 --- a/argos/server/routes/api_app.py +++ b/argos/server/routes/api_app.py @@ -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, } diff --git a/argos/server/routes/views.py b/argos/server/routes/views.py index b79fcb1..b0681e6 100644 --- a/argos/server/routes/views.py +++ b/argos/server/routes/views.py @@ -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, diff --git a/argos/server/templates/index.html b/argos/server/templates/index.html index e4fccef..2a86043 100644 --- a/argos/server/templates/index.html +++ b/argos/server/templates/index.html @@ -11,6 +11,9 @@ {{ agents | length }} agent{{ 's' if agents | length > 1 }} +