From 5519d7ca9517263875bbb475da42b757712fb5d5 Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Thu, 24 Jan 2019 14:58:36 +0100 Subject: bin/cleanup: only keep 1 log instead of 10 --- bin/cleanup | 49 +++++++++++++++++++------------------------------ 1 file changed, 19 insertions(+), 30 deletions(-) (limited to 'bin/cleanup') diff --git a/bin/cleanup b/bin/cleanup index 206b84c..57c4e07 100755 --- a/bin/cleanup +++ b/bin/cleanup @@ -19,41 +19,30 @@ if [ -s "${work_dir}/build-master-sanity" ]; then exit fi -# only keep 10 newest logs per failed package and fail_reason +# only keep newest logs per failed package and fail_reason # shellcheck disable=SC2016 { - printf 'SELECT' - printf ' CONCAT(`failed_builds`.`reason`,"-",`failed_builds`.`build_assignment`),' - printf '`failed_builds`.`id`,' - printf '`failed_builds`.`log_file`' + printf 'DELETE `failed_builds`' 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' + printf ' LEFT JOIN (' + printf 'SELECT' + printf ' `failed_builds`.`reason`,' + printf '`failed_builds`.`build_assignment`,' + printf ' MAX(`failed_builds`.`date`) AS `max_date`' + printf ' FROM `failed_builds`' + printf ' GROUP BY CONCAT(`failed_builds`.`reason`,"-",`failed_builds`.`build_assignment`)' + printf ') AS `last_log_q`' + printf ' AND `last_log_q`.`%s`=`failed_builds`.`%s`' \ + 'max_date' 'date' \ + 'reason' 'reason' \ + 'build_assignment' 'build_assignment' \ + | sed ' + s/^ AND / ON / + ' + printf ' WHERE `last_log_q`.`reason` IS NULL;\n' + } | \ - mysql_run_query | \ - { - count=0 - old_group='' - while read -r group id log_file; do - if [ "${group}" != "${old_group}" ]; then - count=0 - old_group="${group}" - fi - if [ ${count} -ge 10 ]; then - 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 # remove logs where package is not broken/locked anymore -- cgit v1.2.3