]> git.ipfire.org Git - pbs.git/commitdiff
jobs: Add option to only show failed builds
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 1 Aug 2023 16:16:37 +0000 (16:16 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 1 Aug 2023 16:16:37 +0000 (16:16 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/jobs.py
src/templates/jobs/index.html
src/web/jobs.py

index 0c7dac3b9186d5843c5fde8ac5cae17f0175ab20..8ee57b67d24ad3ad56fbbfa50729ea5618d6b0db 100644 (file)
@@ -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
                                *
index c9fd8d0e0b43f716f878abc08036769c4cd261f7..4ba249d69102e17aa017fffe711b5473ba7dd4a4 100644 (file)
                                        </ul>
                                </nav>
 
-                               <h1 class="title">{{ _("Recent Jobs") }}</h1>
+                               <h1 class="title">
+                                       {% if failed_only %}
+                                               {{ _("Recently Failed Jobs") }}
+                                       {% else %}
+                                               {{ _("Recent Jobs") }}
+                                       {% end %}
+                               </h1>
+
+                               <div class="buttons are-small">
+                                       <a class="button is-danger {% if not failed_only %}is-outlined{% end %}"
+                                                       href="{{ make_url("/jobs", offset=max(offset - limit, 0), limit=limit, failed_only=not failed_only) }}">
+                                               {{ _("Failed") }}
+                                       </a>
+                               </div>
                        </div>
                </div>
        </section>
                        <div class="block">
                                <nav class="pagination is-centered" role="navigation" aria-label="pagination">
                                        <a class="pagination-previous {% if not offset %}is-disabled{% end %}"
-                                                       href="{{ make_url("/jobs", offset=offset - limit, limit=limit) }}">
+                                                       href="{{ make_url("/jobs", offset=offset - limit, limit=limit, failed_only=failed_only) }}">
                                                {{ _("Previous Page") }}
                                        </a>
 
                                        <a class="pagination-next"
-                                                       href="{{ make_url("/jobs", offset=offset + limit, limit=limit) }}">
+                                                       href="{{ make_url("/jobs", offset=offset + limit, limit=limit, failed_only=failed_only) }}">
                                                {{ _("Next Page") }}
                                        </a>
                                </nav>
index 9e214db892470028c0434068fecaaca621660c38..4556b77169554bd00c25003242c2b705a515bf94 100644 (file)
@@ -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):