return list(packages)
+ @property
+ def pending_jobs(self):
+ """
+ Returns a list of all pending jobs that use this repository
+ as their build repository.
+ """
+ jobs = self.backend.jobs._get_jobs("""
+ SELECT
+ jobs.*
+ FROM
+ builds
+ LEFT JOIN
+ jobs ON builds.id = jobs.build_id
+ -- Only from this repository
+ WHERE
+ builds.build_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,
+ )
+
+ return list(jobs)
+
# Stats
@lazy_property
# Write/rewrite the repository
await self.write()
- # XXX Perform dependency checks on all pending jobs
+ # Relaunch any pending jobs
+ await self.relaunch_pending_jobs()
+
+ async def relaunch_pending_jobs(self):
+ # Perform this on this repository
+ self._relaunch_pending_jobs()
+
+ # Perform this for all sibling repositories
+ # XXX
+ #for repo in self.siblings:
+ # repo._relaunch_pending_jobs()
+
+ def _relaunch_pending_jobs(self):
+ """
+ This function needs to be called whenever the repository has to be
+ changed so that all pending jobs will have their dependencies recalculated.
+ """
+ # Perform dependency checks on all pending jobs
+ self.backend.run_task(self.backend.jobs.launch, self.pending_jobs)
# Write repository
# Repositories
"repos:fetch-sources" : self.backend.repos.fetch_sources,
+ "repos:relaunch-pending-jobs" : self._repos_relaunch_pending_jobs,
"repos:rotate-keys" : self.backend.repos.rotate_keys,
"repos:write" : self.backend.repos.write,
# Launch all builds
await self.backend.builds.launch(builds)
+ async def _repos_relaunch_pending_jobs(self):
+ for repo in sorted(self.backend.repos):
+ await repo.relaunch_pending_jobs()
+
async def main():
cli = Cli()