summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2019-01-24 14:58:36 +0100
committerErich Eckner <git@eckner.net>2019-01-24 14:58:36 +0100
commit5519d7ca9517263875bbb475da42b757712fb5d5 (patch)
tree0fda2151ed2522fbbf54620117e7d9cd7fae0781 /bin
parentba7e75157e06dc5cb03683f8eb33a2a99c61b95e (diff)
downloadbuilder-5519d7ca9517263875bbb475da42b757712fb5d5.tar.xz
bin/cleanup: only keep 1 log instead of 10
Diffstat (limited to 'bin')
-rwxr-xr-xbin/cleanup49
1 files changed, 19 insertions, 30 deletions
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