Passport/pkg/internal/services/ticker_maintainer.go

25 lines
648 B
Go
Raw Normal View History

2024-01-07 07:52:23 +00:00
package services
import (
2024-07-12 03:25:41 +00:00
"time"
"git.solsynth.dev/hydrogen/passport/pkg/internal/database"
"git.solsynth.dev/hydrogen/passport/pkg/internal/models"
"github.com/rs/zerolog/log"
2024-01-07 07:52:23 +00:00
)
func DoAutoSignoff() {
2024-07-12 03:25:41 +00:00
duration := 7 * 24 * time.Hour
deadline := time.Now().Add(-duration)
2024-07-12 03:25:41 +00:00
log.Debug().Time("before", deadline).Msg("Now signing off tickets...")
if tx := database.C.
2024-07-12 03:25:41 +00:00
Where("last_grant_at < ?", deadline).
2024-04-20 11:04:33 +00:00
Delete(&models.AuthTicket{}); tx.Error != nil {
log.Error().Err(tx.Error).Msg("An error occurred when running auto sign off...")
} else {
log.Debug().Int64("affected", tx.RowsAffected).Msg("Auto sign off accomplished.")
}
}