forked from vieter-v/vieter
fix: log removal daemon now properly cleans all old logs
parent
0a3e883f4d
commit
2c93316688
|
@ -18,14 +18,16 @@ fn (mut app App) log_removal_daemon(schedule CronExpression) {
|
||||||
|
|
||||||
app.linfo('Cleaning logs before $too_old_timestamp')
|
app.linfo('Cleaning logs before $too_old_timestamp')
|
||||||
|
|
||||||
mut offset := u64(0)
|
|
||||||
mut logs := []BuildLog{}
|
mut logs := []BuildLog{}
|
||||||
mut counter := 0
|
mut counter := 0
|
||||||
mut failed := 0
|
mut failed := u64(0)
|
||||||
|
|
||||||
// Remove old logs
|
// Remove old logs
|
||||||
for {
|
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 {
|
for log in logs {
|
||||||
log_file_path := os.join_path(app.conf.data_dir, logs_dir_name, log.path())
|
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 {
|
if logs.len < 50 {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
offset += 50
|
|
||||||
}
|
}
|
||||||
|
|
||||||
app.linfo('Cleaned $counter logs ($failed failed)')
|
app.linfo('Cleaned $counter logs ($failed failed)')
|
||||||
|
|
Loading…
Reference in New Issue