This is an automated email from the ASF dual-hosted git repository.

sbp pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tooling-trusted-release.git


The following commit(s) were added to refs/heads/main by this push:
     new a31b432  Add a function and route to get the number of ongoing tasks 
for a draft revision
a31b432 is described below

commit a31b432aa2547e0b70fe2ac923c0ad80d680427a
Author: Sean B. Palmer <[email protected]>
AuthorDate: Tue Apr 15 16:15:07 2025 +0100

    Add a function and route to get the number of ongoing tasks for a draft 
revision
---
 atr/blueprints/admin/admin.py | 10 ++++++++++
 atr/db/__init__.py            | 18 ++++++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/atr/blueprints/admin/admin.py b/atr/blueprints/admin/admin.py
index c01a48f..860bebc 100644
--- a/atr/blueprints/admin/admin.py
+++ b/atr/blueprints/admin/admin.py
@@ -379,6 +379,16 @@ async def admin_toggle_view() -> response.Response:
     return quart.redirect(referrer or quart.url_for("admin.admin_data"))
 
 
[email protected]("/ongoing-tasks/<project_name>/<version_name>/<draft_revision>")
+async def ongoing_tasks(project_name: str, version_name: str, draft_revision: 
str) -> quart.wrappers.response.Response:
+    try:
+        ongoing = await db.tasks_ongoing(project_name, version_name, 
draft_revision)
+        return quart.Response(str(ongoing), mimetype="text/plain")
+    except Exception:
+        _LOGGER.exception(f"Error fetching ongoing task count for 
{project_name} {version_name} rev {draft_revision}:")
+        return quart.Response("", mimetype="text/plain")
+
+
 async def _delete_release_data(release_name: str) -> None:
     """Handle the deletion of database records and filesystem data for a 
release."""
     async with db.session() as data:
diff --git a/atr/db/__init__.py b/atr/db/__init__.py
index 30b317b..54a79de 100644
--- a/atr/db/__init__.py
+++ b/atr/db/__init__.py
@@ -627,6 +627,24 @@ async def shutdown_database() -> None:
         _LOGGER.info("No database to close")
 
 
+async def tasks_ongoing(project_name: str, version_name: str, draft_revision: 
str) -> int:
+    release_name = models.release_name(project_name, version_name)
+    async with session() as data:
+        query = (
+            sqlmodel.select(sqlalchemy.func.count())
+            .select_from(models.Task)
+            .where(
+                models.Task.release_name == release_name,
+                models.Task.draft_revision == draft_revision,
+                validate_instrumented_attribute(models.Task.status).in_(
+                    [models.TaskStatus.QUEUED, models.TaskStatus.ACTIVE]
+                ),
+            )
+        )
+        result = await data.execute(query)
+        return result.scalar_one()
+
+
 def validate_instrumented_attribute(obj: Any) -> orm.InstrumentedAttribute:
     """Check if the given object is an InstrumentedAttribute."""
     if not isinstance(obj, orm.InstrumentedAttribute):


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to