fix: log removal daemon now properly cleans all old logs

main
Jef Roosens 2022-12-19 12:43:46 +01:00
parent 0a3e883f4d
commit 2c93316688
Signed by untrusted user: Jef Roosens
GPG Key ID: B75D4F293C7052DB
1 changed files with 5 additions and 5 deletions

View File

@ -18,14 +18,16 @@ fn (mut app App) log_removal_daemon(schedule CronExpression) {
app.linfo('Cleaning logs before $too_old_timestamp')
mut offset := u64(0)
mut logs := []BuildLog{}
mut counter := 0
mut failed := 0
mut failed := u64(0)
// Remove old logs
for {
logs = app.db.get_build_logs(before: too_old_timestamp, offset: offset, limit: 50)
// The offset is used to skip logs that failed to remove. Besides
// this, we don't need to move the offset, because all previously
// oldest logs will have been removed.
logs = app.db.get_build_logs(before: too_old_timestamp, offset: failed, limit: 50)
for log in logs {
log_file_path := os.join_path(app.conf.data_dir, logs_dir_name, log.path())
@ -44,8 +46,6 @@ fn (mut app App) log_removal_daemon(schedule CronExpression) {
if logs.len < 50 {
break
}
offset += 50
}
app.linfo('Cleaned $counter logs ($failed failed)')