snapshot of https://github.com/traggo/server.git (master, 2026-09-16; blobs > 131072B omitted)
Some checks failed
build / build (push) Failing after 3s

This commit is contained in:
upstream-mirror
2026-09-16 05:24:45 +05:00
commit cda7c1a474
272 changed files with 31973 additions and 0 deletions

29
auth/cleanup.go Normal file
View File

@@ -0,0 +1,29 @@
package auth
import (
"time"
"github.com/jinzhu/gorm"
"github.com/jmattheis/go-timemath"
"github.com/rs/zerolog/log"
"github.com/traggo/server/model"
)
var timeNow = time.Now
// CleanUp clean up expired devices
func CleanUp(db *gorm.DB, interval time.Duration, close chan bool) {
for {
select {
case <-time.After(interval):
affected := db.Where("type = ? AND active_at < ?", model.TypeLongExpiry, timemath.Second.Subtract(timeNow(), model.TypeLongExpiry.Seconds())).
Or("type = ? AND active_at < ?", model.TypeShortExpiry, timemath.Second.Subtract(timeNow(), model.TypeShortExpiry.Seconds())).
Delete(new(model.Device)).RowsAffected
if affected > 0 {
log.Debug().Int64("amount", affected).Msg("removed devices")
}
case <-close:
return
}
}
}