1
mirror of https://gitlab.com/commento/commento.git synced 2026-06-17 09:55:27 -04:00

api: add cron job to clean up views table

This commit is contained in:
Adhityaa Chandrasekar
2019-01-31 02:19:12 -05:00
parent 7be22b091f
commit 94829d9b83
2 changed files with 26 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
package main
import (
"time"
)
func viewsCleanupBegin() error {
go func() {
for {
statement := `
DELETE FROM views
WHERE viewDate < $1;
`
_, err := db.Exec(statement, time.Now().UTC().AddDate(0, 0, -45))
if err != nil {
logger.Errorf("error cleaning up views: %v", err)
return
}
time.Sleep(24 * time.Hour)
}
}()
return nil
}
+1
View File
@@ -12,6 +12,7 @@ func main() {
exitIfError(sigintCleanupSetup())
exitIfError(versionCheckStart())
exitIfError(domainExportCleanupBegin())
exitIfError(viewsCleanupBegin())
exitIfError(routesServe())
}