From df1262225b31473da98aa606999327d4bdff9e24 Mon Sep 17 00:00:00 2001 From: Tomas Kopecek Date: Aug 18 2020 13:55:28 +0000 Subject: 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 --- diff --git a/builder/kojid b/builder/kojid index 9f6d644..91e39b8 100755 --- a/builder/kojid +++ b/builder/kojid @@ -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: diff --git a/hub/kojihub.py b/hub/kojihub.py index 441094a..8953bf0 100644 --- a/hub/kojihub.py +++ b/hub/kojihub.py @@ -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())