From: Michael Tremer Date: Wed, 5 Feb 2025 11:30:36 +0000 (+0000) Subject: repos: Fix relaunching pending jobs X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5796c015e22c4726a4ef96de7b82e2302033123f;p=pbs.git repos: Fix relaunching pending jobs Signed-off-by: Michael Tremer --- diff --git a/src/buildservice/repos.py b/src/buildservice/repos.py index e8b29fef..959b2700 100644 --- a/src/buildservice/repos.py +++ b/src/buildservice/repos.py @@ -662,39 +662,38 @@ class Repo(database.Base, database.BackendMixin, database.SoftDeleteMixin): return self.db.fetch(stmt) @property - async def pending_jobs(self): + def pending_jobs(self): """ - Returns a list of all pending jobs that use this repository - as their build repository. + Returns an iterator of all pending jobs that use + this repository as their build repository. """ - return await self.backend.jobs._get_jobs(""" - SELECT - jobs.* - FROM - builds - LEFT JOIN - jobs ON builds.id = jobs.build_id - -- Only from this repository - WHERE - builds.repo_id = %s - -- Builds must not be deleted - AND - builds.deleted_at IS NULL - -- Jobs must not be deleted - AND - jobs.deleted_at IS NULL - -- Skip any superseeded jobs - AND - jobs.superseeded_by IS NULL - -- Jobs must not be started - AND - jobs.started_at IS NULL - -- Jobs must not be finished - AND - jobs.finished_at IS NULL - """, self.id, + stmt = ( + sqlalchemy + .select( + jobs.Job, + ) + .join( + builds.Build, + builds.Build.id == jobs.Job.build_id, + ) + .where( + builds.Build.deleted_at == None, + jobs.Job.deleted_at == None, + + # Must be in this repository + builds.Build.repo == self, + + # Skip superseeded jobs + jobs.Job.superseeded_by_id == None, + + # Jobs must not have started and not be finished + jobs.Job.started_at == None, + jobs.Job.finished_at == None, + ) ) + return self.db.fetch(stmt) + # Stats async def get_total_size(self): @@ -821,7 +820,9 @@ class Repo(database.Base, database.BackendMixin, database.SoftDeleteMixin): log.debug("%s: Relaunching pending jobs" % self) # Find all jobs that previously failed their installation check - jobs = [job for job in self.pending_jobs if job.is_pending(installcheck=False)] + jobs = [ + job async for job in self.pending_jobs if job.is_pending(installcheck=False) + ] # Perform installcheck on all pending jobs if jobs: