phase1: prioritize builders by branch order
authorThibaut VARÈNE <hacks@slashdirt.org>
Thu, 27 Oct 2022 11:27:56 +0000 (13:27 +0200)
committerPetr Štetiar <ynezz@true.cz>
Mon, 15 May 2023 15:36:01 +0000 (17:36 +0200)
Signed-off-by: Thibaut VARÈNE <hacks@slashdirt.org>
phase1/master.cfg

index ee250e30bc45702352b2c9da44ef17758b3ba09f..0bb23b243058adadeb3e8d520d1d2446d0715ab1 100644 (file)
@@ -205,11 +205,17 @@ def getNewestCompleteTime(bldr):
 @defer.inlineCallbacks
 def prioritizeBuilders(master, builders):
        """Returns sorted list of builders by their last timestamp of completed and
-       not skipped build.
+       not skipped build, ordered first by branch name.
 
        @returns: list of sorted builders
        """
 
+       bldrNamePrio = { "__Janitor": 0, "00_force_build": 0 }
+       i = 1
+       for bname in branchNames:
+               bldrNamePrio[bname] = i
+               i += 1
+
        def is_building(bldr):
                return bool(bldr.building) or bool(bldr.old_building)
 
@@ -221,10 +227,11 @@ def prioritizeBuilders(master, builders):
        def bldr_sort(item):
                (complete_at, bldr) = item
 
-               if bldr.name == "00_force_build":
-                       date = datetime.min
-                       complete_at = date.replace(tzinfo=tzutc())
-                       return (complete_at, bldr.name)
+               pos = 99
+               for (name, prio) in bldrNamePrio.items():
+                       if bldr.name.startswith(name):
+                               pos = prio
+                               break
 
                if not complete_at:
                        date = datetime.min
@@ -234,7 +241,7 @@ def prioritizeBuilders(master, builders):
                        date = datetime.max
                        complete_at = date.replace(tzinfo=tzutc())
 
-               return (complete_at, bldr.name)
+               return (pos, complete_at, bldr.name)
 
        results = yield defer.gatherResults([bldr_info(bldr) for bldr in builders])
        results.sort(key=bldr_sort)
@@ -513,11 +520,6 @@ def GetNextBuild(builder, requests):
                        # order tagged build first
                        if r.properties.hasProperty("tag"):
                                return r
-                       # then order by branch order
-                       pbranch = r.properties.getProperty("branch")
-                       for name in branchNames:
-                               if pbranch == name:
-                                       return r
 
        r = requests[0]
        log.msg("GetNextBuild: {:>20} id: {} bsid: {}".format(builder.name, r.id, r.bsid))