From: Michael Tremer Date: Sat, 18 Jun 2022 12:03:36 +0000 (+0000) Subject: hub: Orders builders by how busy they are X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e23d46fafe0c95bd81e5d7d6d72a00fa8587b582;p=pbs.git hub: Orders builders by how busy they are The queue will evaluate every builder once and will check those with fewer running jobs first, so that they will get jobs first. Signed-off-by: Michael Tremer --- diff --git a/src/hub/queue.py b/src/hub/queue.py index 169d587a..92aca941 100644 --- a/src/hub/queue.py +++ b/src/hub/queue.py @@ -41,11 +41,16 @@ def dispatch_jobs(backend): log.debug(" No connections open") return - # Process all connections + builders = {} + + # Map all connections by builder for connection in connections: - builder = connection.builder + builders[connection.builder] = connection - log.debug(" Processing connection for %s" % builder) + # Process all builders and assign jobs + # We prioritize builders with fewer jobs + for builder in sorted(builders, key=lambda b: len(b.jobs)): + log.debug(" Processing builder %s" % builder) with backend.db.transaction(): if not builder.is_ready(): @@ -60,6 +65,9 @@ def dispatch_jobs(backend): job.builder = builder + # Find the connection + connection = builders[builder] + # Send the job to the builder connection.assign_job(job)