Passport/pkg/services/ticker_maintainer.go

25 lines
711 B
Go
Raw Normal View History

2024-01-07 07:52:23 +00:00
package services
import (
2024-04-13 05:48:19 +00:00
"git.solsynth.dev/hydrogen/passport/pkg/database"
"git.solsynth.dev/hydrogen/passport/pkg/models"
"github.com/rs/zerolog/log"
2024-02-18 08:26:46 +00:00
"github.com/spf13/viper"
2024-04-20 11:04:33 +00:00
"time"
2024-01-07 07:52:23 +00:00
)
func DoAutoSignoff() {
duration := time.Duration(viper.GetInt64("security.auto_signoff_duration")) * time.Second
divider := time.Now().Add(-duration)
2024-04-21 04:20:06 +00:00
log.Debug().Time("before", divider).Msg("Now signing off tickets...")
if tx := database.C.
Where("last_grant_at < ?", divider).
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.")
}
}