2024-01-07 07:52:23 +00:00
|
|
|
package services
|
|
|
|
|
|
|
|
import (
|
2024-07-12 03:25:41 +00:00
|
|
|
"time"
|
|
|
|
|
2024-06-17 14:21:34 +00:00
|
|
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/database"
|
|
|
|
"git.solsynth.dev/hydrogen/passport/pkg/internal/models"
|
2024-03-23 05:04:25 +00:00
|
|
|
"github.com/rs/zerolog/log"
|
2024-01-07 07:52:23 +00:00
|
|
|
)
|
|
|
|
|
2024-03-23 05:04:25 +00:00
|
|
|
func DoAutoSignoff() {
|
2024-07-12 03:25:41 +00:00
|
|
|
duration := 7 * 24 * time.Hour
|
|
|
|
deadline := time.Now().Add(-duration)
|
2024-03-23 05:04:25 +00:00
|
|
|
|
2024-07-12 03:25:41 +00:00
|
|
|
log.Debug().Time("before", deadline).Msg("Now signing off tickets...")
|
2024-03-23 05:04:25 +00:00
|
|
|
|
|
|
|
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 {
|
2024-03-23 05:04:25 +00:00
|
|
|
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.")
|
|
|
|
}
|
|
|
|
}
|