From: Michael Tremer Date: Thu, 23 Jan 2025 14:05:21 +0000 (+0000) Subject: jobs: Fix showing logs X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3d6478fa736d62434765c9e3e2cfbf227ad2e6f8;p=pbs.git jobs: Fix showing logs Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/jobs.py b/src/buildservice/jobs.py index 4f076051..e878435f 100644 --- a/src/buildservice/jobs.py +++ b/src/buildservice/jobs.py @@ -565,36 +565,16 @@ class Job(database.Base, database.BackendMixin, database.SoftDeleteMixin): """ A list of jobs that came before this one """ - jobs = self.backend.jobs._get_jobs(""" - WITH RECURSIVE preceeding_jobs AS ( - SELECT - jobs.* - FROM - jobs - WHERE - jobs.superseeded_by = %s - - UNION ALL + jobs = [] - SELECT - jobs.* - FROM - jobs - INNER JOIN - preceeding_jobs ON preceeding_jobs.id = jobs.superseeded_by - ) + for job in self.build.alljobs: + if not job.superseeded_by == self: + continue - SELECT - * - FROM - preceeding_jobs jobs - WHERE - jobs.deleted_at IS NULL - ORDER BY - jobs.created_at DESC - """, self.id) + jobs.append(job) + jobs.extend(job.preceeding_jobs) - return list(jobs) + return sorted(jobs) @property def all_jobs(self): @@ -931,6 +911,17 @@ class Job(database.Base, database.BackendMixin, database.SoftDeleteMixin): return False + def show_log(self): + """ + Helper function because we cannot use any() in the templates. + + Is returns True if we should show the "View Log" option. + """ + if self.is_running(): + return True + + return any(job.has_log() for job in self.all_jobs) + @property def log_url(self): return self.backend.path_to_url(self.log_path) diff --git a/src/templates/jobs/macros.html b/src/templates/jobs/macros.html index effdca8d..d056f72c 100644 --- a/src/templates/jobs/macros.html +++ b/src/templates/jobs/macros.html @@ -125,19 +125,10 @@ - {% set has_log = False %} - - {# Does at last one job have a log? #} - {% for job in job.all_jobs %} - {% if job.has_log() %} - {% set has_log = True %} - {% endif %} - {% endfor %} -
- {% if has_log or job.is_running() %} + {% if job.show_log() %} {% if job.preceeding_jobs %}