summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorBlaster4385 <venkatesh@tablaster.dev>2024-07-25 17:05:15 +0530
committerBlaster4385 <venkatesh@tablaster.dev>2024-07-25 17:16:08 +0530
commit330f38289a0c83b60a6ab4a310e6bee24e2fe2a5 (patch)
tree107ce6b3b282889e6e5f5721fd39ed37a48e0f32 /server
parentb933d6ab405fdda250a26c86f23586da82f66fe9 (diff)
feat: cleanup files older than 1 day
Diffstat (limited to 'server')
-rw-r--r--server/main.go11
1 files changed, 11 insertions, 0 deletions
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)
+ }
+}