Skip to content

Commit

Permalink
Make branch prioritisation more general with a sorting function
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
cvicentiu committed Jan 7, 2025
1 parent e596b41 commit c7f19cf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion common_factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
mtrJobsMultiplier,
printEnv,
saveLogs,
savePackage,
savePackageIfBranchMatch,
)


Expand Down
22 changes: 13 additions & 9 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit c7f19cf

Please sign in to comment.