api: add cron job to clean up views table
This commit is contained in:
parent
7be22b091f
commit
94829d9b83
25
api/cron_views_cleanup.go
Normal file
25
api/cron_views_cleanup.go
Normal 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
|
||||||
|
}
|
@ -12,6 +12,7 @@ func main() {
|
|||||||
exitIfError(sigintCleanupSetup())
|
exitIfError(sigintCleanupSetup())
|
||||||
exitIfError(versionCheckStart())
|
exitIfError(versionCheckStart())
|
||||||
exitIfError(domainExportCleanupBegin())
|
exitIfError(domainExportCleanupBegin())
|
||||||
|
exitIfError(viewsCleanupBegin())
|
||||||
|
|
||||||
exitIfError(routesServe())
|
exitIfError(routesServe())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user