From d405b34747e26583188e0fed74eada853d7542fa Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Fri, 12 Jul 2024 11:25:41 +0800 Subject: [PATCH] :bug: Bug fixes on cron jobs --- pkg/internal/services/cleaner.go | 8 +++----- pkg/internal/services/ticker_maintainer.go | 12 ++++++------ settings.toml | 1 - 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/pkg/internal/services/cleaner.go b/pkg/internal/services/cleaner.go index d124f3e..2a33319 100644 --- a/pkg/internal/services/cleaner.go +++ b/pkg/internal/services/cleaner.go @@ -3,18 +3,16 @@ package services import ( "git.solsynth.dev/hydrogen/passport/pkg/internal/database" "github.com/rs/zerolog/log" - "time" ) func DoAutoDatabaseCleanup() { - deadline := time.Now().Add(60 * time.Minute) - log.Debug().Time("deadline", deadline).Msg("Now cleaning up entire database...") + log.Debug().Msg("Now cleaning up entire database...") var count int64 for _, model := range database.AutoMaintainRange { - tx := database.C.Unscoped().Delete(model, "deleted_at >= ?", deadline) + tx := database.C.Unscoped().Delete(model, "deleted_at IS NOT NULL") if tx.Error != nil { - log.Error().Err(tx.Error).Msg("An error occurred when running auth context cleanup...") + log.Error().Err(tx.Error).Msg("An error occurred when running cleaning up entire database...") } count += tx.RowsAffected } diff --git a/pkg/internal/services/ticker_maintainer.go b/pkg/internal/services/ticker_maintainer.go index 78fdcf7..c44ae45 100644 --- a/pkg/internal/services/ticker_maintainer.go +++ b/pkg/internal/services/ticker_maintainer.go @@ -1,21 +1,21 @@ package services import ( + "time" + "git.solsynth.dev/hydrogen/passport/pkg/internal/database" "git.solsynth.dev/hydrogen/passport/pkg/internal/models" "github.com/rs/zerolog/log" - "github.com/spf13/viper" - "time" ) func DoAutoSignoff() { - duration := time.Duration(viper.GetInt64("security.auto_signoff_duration")) * time.Second - divider := time.Now().Add(-duration) + duration := 7 * 24 * time.Hour + deadline := time.Now().Add(-duration) - log.Debug().Time("before", divider).Msg("Now signing off tickets...") + log.Debug().Time("before", deadline).Msg("Now signing off tickets...") if tx := database.C. - Where("last_grant_at < ?", divider). + Where("last_grant_at < ?", deadline). Delete(&models.AuthTicket{}); tx.Error != nil { log.Error().Err(tx.Error).Msg("An error occurred when running auto sign off...") } else { diff --git a/settings.toml b/settings.toml index 945ad7e..5fc0b4f 100644 --- a/settings.toml +++ b/settings.toml @@ -35,7 +35,6 @@ password = "gz937Zxxzfcd9SeH" [security] cookie_domain = "localhost" cookie_samesite = "Lax" -auto_signoff_duration = 86400 access_token_duration = 300 refresh_token_duration = 2592000