diff options
-rwxr-xr-x | bin/harvest-commit-times | 31 |
1 files changed, 28 insertions, 3 deletions
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 |