diff options
author | Erich Eckner <git@eckner.net> | 2018-06-18 11:05:42 +0200 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2018-06-18 11:05:42 +0200 |
commit | 14f8cddb8a8d38c8cc07df54cfad7cb2aa0fb594 (patch) | |
tree | 09b855158dd0252ecbd8fbe37ef6f0726b694c19 | |
parent | c0e2e2a802f3eb7203dac1433d1b2935e67f0955 (diff) | |
download | builder-14f8cddb8a8d38c8cc07df54cfad7cb2aa0fb594.tar.xz |
bin/cleanup: keep 10 newest logs of each build_assignment _and_ fail_reason
-rwxr-xr-x | bin/cleanup | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/bin/cleanup b/bin/cleanup index 09a823b..fe4f34e 100755 --- a/bin/cleanup +++ b/bin/cleanup @@ -41,26 +41,42 @@ fi rm "${build_log_directory}/error/${file}" done -# only keep 10 newest logs per failed package +# only keep 10 newest logs per failed package and fail_reason -find "${build_log_directory}/error" -maxdepth 1 -type f -printf '%f\n' | \ - sed 's|^\(.*\)\(\.\([^.]\+\)\.build-log\.gz\)$|\1\2 \3 \1|' | \ - sort -k3,3 -k2r,2 | \ - uniq -f2 --group=prepend | \ - cut -d' ' -f1 | \ +# shellcheck disable=SC2016 +{ + printf 'SELECT' + printf ' CONCAT(`failed_builds`.`reason`,"-",`failed_builds`.`build_assignment`),' + printf '`failed_builds`.`id`,' + printf '`failed_builds`.`log_file`' + printf ' FROM `failed_builds`' + printf ' WHERE `log_file_exists`' + printf ' ORDER BY' + printf ' `failed_builds`.`reason`,' + printf '`failed_builds`.`build_assignment`,' + printf '`failed_builds`.`date` DESC;\n' +} | \ + mysql_run_query | \ { count=0 - while read -r a; do - if [ -z "${a}" ]; then + old_group='' + while read -r group id log_file; do + if [ "${group}" != "${old_group}" ]; then count=0 - continue + old_group="${group}" fi if [ ${count} -ge 10 ]; then - rm "${build_log_directory}/error/${a}" + rm "${build_log_directory}/error/${log_file}" + printf '%s,' "${id}" fi count=$((count+1)) done - } + } | \ + sed ' + s/,$/);\n/ + s/^/DELETE FROM `failed_builds` WHERE `failed_builds`.`id` IN (/ + ' | \ + mysql_run_query # only keep namcap logs of last 2 weeks for succeeded packages find "${build_log_directory}/success" -maxdepth 1 -type f -mtime +14 \ |