-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbackground_jobs.go
More file actions
35 lines (27 loc) · 881 Bytes
/
Copy pathbackground_jobs.go
File metadata and controls
35 lines (27 loc) · 881 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package main
import (
"fmt"
"time"
)
const (
backgroundJobClearData = "clear_data"
)
func (server *serverStruct) clearDataBackgroundJob() {
for {
now := time.Now().UTC()
nextMidnight := time.Date(now.Year(), now.Month(), now.Day()+1, 0, 0, 0, 0, time.UTC)
time.Sleep(time.Until(nextMidnight))
runId := generateLongItemId()
server.logBackgroundJobRun(runId, backgroundJobClearData)
err := server.cleanDatabase()
if err != nil {
errorMessage := fmt.Sprintf("failed to clean database: %s", err.Error())
server.logBackgroundJobError(runId, backgroundJobClearData, errorMessage)
}
server.userPasswordAuthenticationRateLimit.Clear()
server.emailAddressVerificationRateLimit.Clear()
server.userPasswordResetCodeVerificationRateLimit.Clear()
server.emailRateLimit.Clear()
server.logBackgroundJobRunCompletion(runId, backgroundJobClearData)
}
}