diff --git a/api/cron_sso_token.go b/api/cron_sso_token.go new file mode 100644 index 0000000..ce1c18a --- /dev/null +++ b/api/cron_sso_token.go @@ -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 +} diff --git a/api/main.go b/api/main.go index 148b48c..faa0324 100644 --- a/api/main.go +++ b/api/main.go @@ -16,6 +16,7 @@ func main() { exitIfError(versionCheckStart()) exitIfError(domainExportCleanupBegin()) exitIfError(viewsCleanupBegin()) + exitIfError(ssoTokenCleanupBegin()) exitIfError(routesServe()) }