]> git.ipfire.org Git - pbs.git/commitdiff
hub: Orders builders by how busy they are
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 18 Jun 2022 12:03:36 +0000 (12:03 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 18 Jun 2022 12:03:36 +0000 (12:03 +0000)
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 <michael.tremer@ipfire.org>
src/hub/queue.py

index 169d587a32af3d60e0903643d0d808884d82bd37..92aca941b7b48fec9c5efda52274a73bd949a1a5 100644 (file)
@@ -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)