main.go: add cron to auto cleanup SSO tokens

This commit is contained in:
Adhityaa Chandrasekar 2019-04-20 23:30:34 -04:00
parent 6317b384d9
commit cac1cfa84a
2 changed files with 26 additions and 0 deletions

25
api/cron_sso_token.go Normal file
View File

@ -0,0 +1,25 @@
package main
import (
"time"
)
func ssoTokenCleanupBegin() error {
go func() {
for {
statement := `
DELETE FROM ssoTokens
WHERE creationDate < $1;
`
_, err := db.Exec(statement, time.Now().UTC().Add(time.Duration(-10)*time.Minute))
if err != nil {
logger.Errorf("error cleaning up export rows: %v", err)
return
}
time.Sleep(10 * time.Minute)
}
}()
return nil
}

View File

@ -16,6 +16,7 @@ func main() {
exitIfError(versionCheckStart())
exitIfError(domainExportCleanupBegin())
exitIfError(viewsCleanupBegin())
exitIfError(ssoTokenCleanupBegin())
exitIfError(routesServe())
}