watchyourlan/backend/internal/routines/trim-history.go
2025-09-05 06:10:16 +07:00

28 lines
597 B
Go

package routines
import (
"log/slog"
"time"
"github.com/aceberg/WatchYourLAN/internal/conf"
"github.com/aceberg/WatchYourLAN/internal/gdb"
)
// HistoryTrim - routine for History
func HistoryTrim() {
go func() {
for {
time.Sleep(time.Duration(1) * time.Hour) // Every hour
hours := conf.AppConfig.TrimHist
nowMinus := time.Now().Add(-time.Duration(hours) * time.Hour)
date := nowMinus.Format("2006-01-02 15:04:05")
slog.Info("Removing all History before", "date", date)
n := gdb.DeleteOldHistory(date)
slog.Info("Removed records from History", "n", n)
}
}()
}