From: Michael Tremer Date: Tue, 1 Aug 2023 16:16:37 +0000 (+0000) Subject: jobs: Add option to only show failed builds X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a89bb0c860c7713939d79deab285ec9cb9a48c75;p=pbs.git jobs: Add option to only show failed builds Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/jobs.py b/src/buildservice/jobs.py index 0c7dac3b..8ee57b67 100644 --- a/src/buildservice/jobs.py +++ b/src/buildservice/jobs.py @@ -102,10 +102,30 @@ class Jobs(base.Object): def get_by_uuid(self, uuid): return self._get_job("SELECT * FROM jobs WHERE uuid = %s", uuid) - def get_finished(self, limit=None, offset=None): + def get_finished(self, failed_only=False, limit=None, offset=None): """ Returns an iterator of all finished jobs """ + if failed_only: + return self._get_jobs(""" + SELECT + * + FROM + jobs + WHERE + deleted_at IS NULL + AND + finished_at IS NOT NULL + AND + failed IS TRUE + ORDER BY + finished_at DESC + LIMIT + %s + OFFSET + %s + """, limit, offset) + return self._get_jobs(""" SELECT * diff --git a/src/templates/jobs/index.html b/src/templates/jobs/index.html index c9fd8d0e..4ba249d6 100644 --- a/src/templates/jobs/index.html +++ b/src/templates/jobs/index.html @@ -16,7 +16,20 @@ -

{{ _("Recent Jobs") }}

+

+ {% if failed_only %} + {{ _("Recently Failed Jobs") }} + {% else %} + {{ _("Recent Jobs") }} + {% end %} +

+ + @@ -35,12 +48,12 @@
diff --git a/src/web/jobs.py b/src/web/jobs.py index 9e214db8..4556b771 100644 --- a/src/web/jobs.py +++ b/src/web/jobs.py @@ -146,13 +146,18 @@ class IndexHandler(base.BaseHandler): offset = self.get_argument_int("offset", None) or 0 limit = self.get_argument_int("limit", None) or 50 + # Filter + failed_only = self.get_argument_bool("failed_only") + with self.db.transaction(): - jobs = self.backend.jobs.get_finished(limit=limit, offset=offset) + jobs = self.backend.jobs.get_finished(failed_only=failed_only, + limit=limit, offset=offset) # Group jobs by date jobs = misc.group(jobs, lambda job: job.finished_at.date()) - self.render("jobs/index.html", jobs=jobs, limit=limit, offset=offset) + self.render("jobs/index.html", jobs=jobs, limit=limit, offset=offset, + failed_only=failed_only) class LogHandler(base.BaseHandler):