1
0
mirror of https://github.com/JustKato/FreePad.git synced 2026-02-23 15:50:46 +02:00

+ Cleanup timer for old files

This commit is contained in:
2022-05-20 01:59:53 +03:00
parent 051a8a311c
commit cf62661399
4 changed files with 83 additions and 13 deletions

View File

@@ -1,22 +1,36 @@
package controllers
import (
"fmt"
"os"
"strconv"
"time"
"github.com/JustKato/FreePad/lib/objects"
)
func TaskManager() {
// Run the migrations function
go handleMigrations()
// Get the cleanup interval
cleanupIntervalString, exists := os.LookupEnv("CLEANUP_MAX_AGE")
if !exists {
cleanupIntervalString = "-1"
}
for range time.Tick(time.Second * 5) {
// fmt.Printf("%s\n", time.Now().Format("02/01/2006 03:04 PM"))
if cleanupIntervalString == "-1" {
// Do not cleanup
return
}
// Try and parse the string as an int
cleanupInterval, err := strconv.Atoi(cleanupIntervalString)
if err != nil {
cleanupInterval = 1
}
fmt.Println("[Task::Cleanup]: Task registered")
for range time.Tick(time.Minute * 5) {
objects.CleanupPosts(cleanupInterval)
}
}
func handleMigrations() {
time.AfterFunc(time.Second*30, func() {
// Run Migrations
})
}