From cac1cfa84abe3fbc97653a37951858b13b726e93 Mon Sep 17 00:00:00 2001 From: Adhityaa Chandrasekar Date: Sat, 20 Apr 2019 23:30:34 -0400 Subject: [PATCH] main.go: add cron to auto cleanup SSO tokens --- api/cron_sso_token.go | 25 +++++++++++++++++++++++++ api/main.go | 1 + 2 files changed, 26 insertions(+) create mode 100644 api/cron_sso_token.go 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()) }