1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

chore: introduce dry run flag for data cleanup [skip ci]

This commit is contained in:
Ferdinand Mütsch 2023-01-18 09:26:01 +01:00
parent 8ccfcef8e3
commit a1048d480a
2 changed files with 5 additions and 0 deletions

View File

@ -79,6 +79,7 @@ type appConfig struct {
HeartbeatMaxAge string `yaml:"heartbeat_max_age" default:"4320h" env:"WAKAPI_HEARTBEAT_MAX_AGE"` HeartbeatMaxAge string `yaml:"heartbeat_max_age" default:"4320h" env:"WAKAPI_HEARTBEAT_MAX_AGE"`
CountCacheTTLMin int `yaml:"count_cache_ttl_min" default:"30" env:"WAKAPI_COUNT_CACHE_TTL_MIN"` CountCacheTTLMin int `yaml:"count_cache_ttl_min" default:"30" env:"WAKAPI_COUNT_CACHE_TTL_MIN"`
DataRetentionMonths int `yaml:"data_retention_months" default:"-1" env:"WAKAPI_DATA_RETENTION_MONTHS"` DataRetentionMonths int `yaml:"data_retention_months" default:"-1" env:"WAKAPI_DATA_RETENTION_MONTHS"`
DataCleanupDryRun bool `yaml:"data_cleanup_dry_run" default:"false" env:"WAKAPI_DATA_CLEANUP_DRY_RUN"` // for debugging only
AvatarURLTemplate string `yaml:"avatar_url_template" default:"api/avatar/{username_hash}.svg" env:"WAKAPI_AVATAR_URL_TEMPLATE"` AvatarURLTemplate string `yaml:"avatar_url_template" default:"api/avatar/{username_hash}.svg" env:"WAKAPI_AVATAR_URL_TEMPLATE"`
SupportContact string `yaml:"support_contact" default:"hostmaster@wakapi.dev" env:"WAKAPI_SUPPORT_CONTACT"` SupportContact string `yaml:"support_contact" default:"hostmaster@wakapi.dev" env:"WAKAPI_SUPPORT_CONTACT"`
CustomLanguages map[string]string `yaml:"custom_languages"` CustomLanguages map[string]string `yaml:"custom_languages"`

View File

@ -66,6 +66,10 @@ func (s *HousekeepingService) Schedule() {
func (s *HousekeepingService) CleanUserDataBefore(user *models.User, before time.Time) error { func (s *HousekeepingService) CleanUserDataBefore(user *models.User, before time.Time) error {
logbuch.Warn("cleaning up user data for '%s' older than %v", user.ID, before) logbuch.Warn("cleaning up user data for '%s' older than %v", user.ID, before)
if s.config.App.DataCleanupDryRun {
logbuch.Info("skipping actual data deletion for '%v', because this is just a dry run", user.ID)
return nil
}
// clear old heartbeats // clear old heartbeats
if err := s.heartbeatSrvc.DeleteByUserBefore(user, before); err != nil { if err := s.heartbeatSrvc.DeleteByUserBefore(user, before); err != nil {