From 20ad7b8c89a6a0d53a15ecb8f5d7be5676fd8b5c Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Wed, 26 Sep 2018 09:39:07 +0200 Subject: bin/harvest-commit-times: make usfully executable from remote (e.g. not the build master) --- bin/harvest-commit-times | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'bin/harvest-commit-times') diff --git a/bin/harvest-commit-times b/bin/harvest-commit-times index 38d84c4..325da70 100755 --- a/bin/harvest-commit-times +++ b/bin/harvest-commit-times @@ -61,6 +61,13 @@ fi tmp_file=$(mktemp 'tmp.harvest-commit-times.XXXXXXXXXX' --tmpdir) trap 'rm "${tmp_file}"' EXIT +if ! ${i_am_the_master}; then + tmp_remote_file=$( + ssh buildmaster "mktemp 'tmp.harvest-commit-times.remotely.XXXXXXXXXX' --tmpdir" + ) + trap 'rm "${tmp_file}"; ssh buildmaster rm "${tmp_remote_file}"' EXIT +fi + while true; do # shellcheck disable=SC2016 @@ -77,6 +84,9 @@ while true; do mysql_join_upstream_repositories_git_repositories printf ' WHERE `package_sources`.`commit_time`="0000-00-00 00:00:00"' printf ' AND `package_sources`.`uses_upstream`' + if ! ${i_am_the_master}; then + printf ' ORDER BY RAND()' + fi printf ' LIMIT 10' } | \ mysql_run_query 'unimportant' | \ @@ -100,19 +110,34 @@ while true; do done > \ "${tmp_file}" + >&2 printf '.' + if [ -s "${tmp_file}" ]; then + if ! ${i_am_the_master}; then + ssh buildmaster 'cat > "'"${tmp_remote_file}"'"' < \ + "${tmp_file}" + fi # shellcheck disable=SC2016 { printf 'CREATE TEMPORARY TABLE `cts` (`id` BIGINT, `ct` BIGINT);\n' - printf 'LOAD DATA LOCAL INFILE "%s" INTO TABLE `cts`(`id`,`ct`);\n' \ - "${tmp_file}" + if ${i_am_the_master}; then + printf 'LOAD DATA LOCAL INFILE "%s" INTO TABLE `cts`(`id`,`ct`);\n' \ + "${tmp_file}" + else + printf 'LOAD DATA LOCAL INFILE "%s" INTO TABLE `cts`(`id`,`ct`);\n' \ + "${tmp_remote_file}" + fi printf 'UPDATE `cts`' printf ' JOIN `package_sources`' printf ' ON `package_sources`.`id`=`cts`.`id`' printf ' AND `package_sources`.`commit_time`="0000-00-00 00:00:00"' printf ' SET `package_sources`.`commit_time`=from_unixtime(`cts`.`ct`);\n' } | \ - mysql_run_query 'unimportant' + if ${i_am_the_master}; then + mysql_run_query 'unimportant' + else + ssh buildmaster 'mysql buildmaster -N --raw --batch' + fi else break fi -- cgit v1.2.3-70-g09d2