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):
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: