🐛 Bug fixes on cron jobs
This commit is contained in:
		| @@ -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 | ||||
| 	} | ||||
|   | ||||
| @@ -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 { | ||||
|   | ||||
| @@ -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 | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user