From 70ea93947fb2c9c3a799d7319f45dec5aab4415c Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Mon, 24 Jun 2019 11:53:39 +0200 Subject: lib/mysql-functions: mysql_determine_majority_build_slave_architecture_id() new --- lib/mysql-functions | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'lib') 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 +} -- cgit v1.2.3-54-g00ecf