From c7f19cfd32a710c859399bdd17fe8854d6b73876 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vicen=C8=9Biu=20Ciorbaru?= Date: Tue, 26 Nov 2024 14:51:32 +0200 Subject: [PATCH] Make branch prioritisation more general with a sorting function The sorting key sorts in the following priority order: 1. First release branches 2. Next branches that create packages 3. Finally, first come, first serve. This sort key has the added benefit of ensuring that for equal priority build requests, the one that was first in queue is the first picked up. Buildbot documentation does not make any guarantees that the initial requests list is sorted by submit time. --- common_factories.py | 2 +- utils.py | 22 +++++++++++++--------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/common_factories.py b/common_factories.py index 47407024..b542d075 100644 --- a/common_factories.py +++ b/common_factories.py @@ -35,7 +35,7 @@ mtrJobsMultiplier, printEnv, saveLogs, - savePackage, + savePackageIfBranchMatch, ) diff --git a/utils.py b/utils.py index 6332961c..08ff01ec 100644 --- a/utils.py +++ b/utils.py @@ -281,15 +281,19 @@ def fnmatch_any(branch: str, patterns: list[str]) -> bool: # Priority filter based on saved package branches -def nextBuild(builder: Builder, - requests: list[BuildRequest]) -> str: - for r in requests: - if fnmatch_any(r.sources[""].branch, releaseBranches): - return r - for r in requests: - if fnmatch_any(r.sources[""].branch, savedPackageBranches): - return r - return requests[0] +def nextBuild(builder: Builder, requests: list[BuildRequest]) -> str: + def build_request_sort_key(request: BuildRequest): + branch = request.sources[""].branch + # Booleans are sorted False first. + # Priority is given to releaseBranches, savePackageBranches + # then it's first come, first serve. + return ( + not fnmatch_any(branch, releaseBranches), + not fnmatch_any(branch, savedPackageBranches), + request.getSubmitTime(), + ) + + return sorted(requests, build_request_sort_key)[0] def canStartBuild(