From 330f38289a0c83b60a6ab4a310e6bee24e2fe2a5 Mon Sep 17 00:00:00 2001 From: Blaster4385 Date: Thu, 25 Jul 2024 17:05:15 +0530 Subject: [PATCH] feat: cleanup files older than 1 day --- server/main.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/server/main.go b/server/main.go index b7bd5b7..9186ab1 100644 --- a/server/main.go +++ b/server/main.go @@ -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) + } +}