summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2019-06-24 11:53:39 +0200
committerErich Eckner <git@eckner.net>2019-06-24 13:14:01 +0200
commit70ea93947fb2c9c3a799d7319f45dec5aab4415c (patch)
tree55086e8d4f56fc35807db8f839579e4774af0bbc /lib
parent016ff18a1876c0d2e1696dbe82d5a8438ea3cd5c (diff)
downloadbuilder-70ea93947fb2c9c3a799d7319f45dec5aab4415c.tar.xz
lib/mysql-functions: mysql_determine_majority_build_slave_architecture_id() new
Diffstat (limited to 'lib')
-rwxr-xr-xlib/mysql-functions21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/mysql-functions b/lib/mysql-functions
index 67e49aa..59a649e 100755
--- a/lib/mysql-functions
+++ b/lib/mysql-functions
@@ -1503,3 +1503,24 @@ mysql_query_ordering_correct() {
'
printf ')'
}
+
+# mysql_determine_majority_build_slave_architecture_id
+# retreive the `architectures`.`id` of the majority of the currently
+# active build slaves
+mysql_determine_majority_build_slave_architecture_id() {
+ {
+ printf 'SELECT'
+ printf ' COUNT(DISTINCT `ssh_log`.`id`) AS `count`,'
+ printf '`architectures`.`id`'
+ printf ' FROM `ssh_log`'
+ printf ' JOIN `architectures`'
+ printf ' ON `ssh_log`.`parameters`=CONCAT(`architectures`.`name`," ")'
+ printf ' WHERE `action`="get-assignment"'
+ printf ' AND `ssh_log`.`date`>ADDTIME(NOW(),"-1 00:00:00")'
+ printf ' GROUP BY `ssh_log`.`parameters`'
+ printf ' ORDER BY `count` DESC'
+ printf ' LIMIT 1'
+ } | \
+ mysql_run_query | \
+ cut -f2
+}