]> git.ipfire.org Git - pbs.git/commitdiff
repos: Fix relaunching pending jobs
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 5 Feb 2025 11:30:36 +0000 (11:30 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 5 Feb 2025 11:30:36 +0000 (11:30 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/buildservice/repos.py

index e8b29fef03bb5e80ac646ca69a7fb0f8c8c4dedb..959b270092b901b2bd4ec2fbd7757b323fb4ae5d 100644 (file)
@@ -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: