refactor(cron): make next function infallible
This commit is contained in:
parent
801a2cd495
commit
86e519a185
8 changed files with 22 additions and 45 deletions
|
|
@ -9,11 +9,7 @@ const fallback_log_removal_frequency = 24 * time.hour
|
|||
|
||||
// log_removal_daemon removes old build logs every `log_removal_frequency`.
|
||||
fn (mut app App) log_removal_daemon(schedule cron.Expression) {
|
||||
mut start_time := time.Time{}
|
||||
|
||||
for {
|
||||
start_time = time.now()
|
||||
|
||||
mut too_old_timestamp := time.now().add_days(-app.conf.max_log_age)
|
||||
|
||||
app.linfo('Cleaning logs before $too_old_timestamp')
|
||||
|
|
@ -51,12 +47,7 @@ fn (mut app App) log_removal_daemon(schedule cron.Expression) {
|
|||
app.linfo('Cleaned $counter logs ($failed failed)')
|
||||
|
||||
// Sleep until the next cycle
|
||||
next_time := schedule.next_from_now() or {
|
||||
app.lerror("Log removal daemon couldn't calculate next time: $err.msg(); fallback to $server.fallback_log_removal_frequency")
|
||||
|
||||
start_time.add(server.fallback_log_removal_frequency)
|
||||
}
|
||||
|
||||
next_time := schedule.next_from_now()
|
||||
time.sleep(next_time - time.now())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Reference in a new issue