feat: cleanup files older than 1 day

This commit is contained in:
Blaster4385 2024-07-25 17:05:15 +05:30
parent b933d6ab40
commit 330f38289a

View file

@ -392,6 +392,7 @@ func startCleanupScheduler() {
go func() {
for range ticker.C {
cleanupChunks()
cleanupOldFiles()
}
}()
}
@ -405,3 +406,13 @@ func cleanupChunks() {
fmt.Printf("error cleaning up chunks: %v\n", err)
}
}
func cleanupOldFiles() {
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Minute)
defer cancel()
_, err := db.ExecContext(ctx, "DELETE FROM files WHERE created_at < NOW() - INTERVAL '1 day'")
if err != nil {
fmt.Printf("error cleaning up old files: %v\n", err)
}
}