PR#2421: hub: getAverageBuildDuration sliding window

Merges #2421
https://pagure.io/koji/pull-request/2421

Fixes: #2420
https://pagure.io/koji/issue/2420
hub: getAverageBuildDuration should look to limited history
This commit is contained in:
Tomas Kopecek 2020-08-18 15:55:28 +02:00
commit df1262225b
2 changed files with 11 additions and 5 deletions

View file

@ -1363,7 +1363,7 @@ class BuildArchTask(BaseBuildTask):
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 = self.session.getAverageBuildDuration(name)
avg = self.session.getAverageBuildDuration(name, age=6)
if not avg:
return
if avg < 0:

View file

@ -11379,11 +11379,15 @@ class RootExports(object):
tag_id = get_tag_id(tag, strict=True)
return maven_tag_archives(tag_id, event_id=event, inherit=inherit)
def getAverageBuildDuration(self, package):
def getAverageBuildDuration(self, package, age=None):
"""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."""
:param int|str package: Package name or id
:param int age: length of history in months
:return float|None: average number of seconds - If package wasn't built
during past age months (or never), None is returned
"""
packageID = get_package_id(package)
if not packageID:
return None
@ -11394,6 +11398,8 @@ class RootExports(object):
WHERE build.pkg_id = %(packageID)i
AND build.state = %(st_complete)i
AND build.task_id IS NOT NULL"""
if age is not None:
query += " AND build.completion_time > NOW() - '%s months'::interval" % int(age)
return _singleValue(query, locals())