diff --git a/builder/kojid b/builder/kojid index eb2fa4c9..686461a2 100755 --- a/builder/kojid +++ b/builder/kojid @@ -1917,10 +1917,23 @@ class BuildArchTask(BaseTaskHandler): Methods = ['buildArch'] def weight(self): - # XXX - this one needs to figure the weight from the package to be - # built return 1.5 + def updateWeight(self, name): + """ + Update the weight of this task based on the package we're building. + weight is scaled from a minimum of 1.5 to a maximum of 6, based on + the average duration of a build of this package. + """ + avg = session.getAverageBuildDuration(name) + if not avg: + return + # increase the task weight by 0.75 for every hour of build duration + adj = (avg / 4800.0) + # cap the adjustment at +4.5 + weight = self.weight() + min(4.5, adj) + session.host.setTaskWeight(self.id, weight) + def srpm_sanity_checks(self, filename): header = koji.get_rpm_header(filename) @@ -1962,6 +1975,8 @@ class BuildArchTask(BaseTaskHandler): # if not h[rpm.RPMTAG_DISTRIBUTION]: # raise koji.BuildError, "the distribution tag is not set in the original srpm" + self.updateWeight(name) + rootopts = { 'repo_id': repo_id } diff --git a/hub/kojihub.py b/hub/kojihub.py index 16d1686a..a201fcfd 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -5366,11 +5366,14 @@ class RootExports(object): tag = get_tag_id(tag,strict=True) return readTaggedRPMS(tag, package=package, arch=arch, event=event,inherit=True,latest=True, rpmsigs=rpmsigs) - def getAverageBuildDuration(self, packageID): - """Get the average duration of a build of a package with - the given ID. Returns a floating-point value indicating the + def getAverageBuildDuration(self, package): + """Get the average duration of a build of the given package. + Returns a floating-point value indicating the average number of seconds the package took to build. If the package has never been built, return None.""" + packageID = get_package_id(package) + if not packageID: + return None st_complete = koji.BUILD_STATES['COMPLETE'] query = """SELECT EXTRACT(epoch FROM avg(build.completion_time - events.time)) FROM build