2022-05-19 01:55:14 +03:00
|
|
|
package controllers
|
|
|
|
|
|
|
|
import (
|
2022-05-20 01:59:53 +03:00
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"strconv"
|
2022-05-19 01:55:14 +03:00
|
|
|
"time"
|
2022-05-20 01:59:53 +03:00
|
|
|
|
|
|
|
"github.com/JustKato/FreePad/lib/objects"
|
2022-05-19 01:55:14 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func TaskManager() {
|
|
|
|
|
2022-05-20 01:59:53 +03:00
|
|
|
// Get the cleanup interval
|
|
|
|
cleanupIntervalString, exists := os.LookupEnv("CLEANUP_MAX_AGE")
|
|
|
|
if !exists {
|
|
|
|
cleanupIntervalString = "-1"
|
|
|
|
}
|
2022-05-19 01:55:14 +03:00
|
|
|
|
2022-05-20 01:59:53 +03:00
|
|
|
if cleanupIntervalString == "-1" {
|
|
|
|
// Do not cleanup
|
|
|
|
return
|
2022-05-19 01:55:14 +03:00
|
|
|
}
|
|
|
|
|
2022-05-20 01:59:53 +03:00
|
|
|
// 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)
|
|
|
|
}
|
2022-05-19 01:55:14 +03:00
|
|
|
|
|
|
|
}
|