go-urlsh/internal/app/routines.go

35 lines
940 B
Go

package app
import (
"context"
"log"
"code.lila.network/adoralaura/go-urlsh/models"
"github.com/jasonlvhit/gocron"
)
func CleanupLoginsCronJob() {
err := gocron.Every(5).Minutes().Do(CleanupLogins)
if err != nil {
return
}
<-gocron.Start()
}
func CleanupLogins() {
_, err := models.DB.NewDelete().Table("logins").Where("expires < NOW()").Exec(context.Background())
if err != nil {
log.Printf("[CleanupLogins] Error deleting logins: %v\n", err)
}
_, err = models.DB.NewDelete().Table("logintransactions").Where("expires < NOW()").Exec(context.Background())
if err != nil {
log.Printf("[CleanupLogins] Error deleting login transactions: %v\n", err)
}
_, err = models.DB.NewDelete().Table("multifactor").Where("expiresat < NOW()").Where("active = false").Exec(context.Background())
if err != nil {
log.Printf("[CleanupLogins] Error deleting login transactions: %v\n", err)
}
//log.Printf("Cleaned up logins")
}