diff --git a/log_outgoing_requests/config_reset.py b/log_outgoing_requests/config_reset.py index c89c52a..5d87de6 100644 --- a/log_outgoing_requests/config_reset.py +++ b/log_outgoing_requests/config_reset.py @@ -4,10 +4,8 @@ from .tasks import reset_config -def schedule_config_reset(config): - reset_after = ( - config.reset_db_save_after or settings.LOG_OUTGOING_REQUESTS_RESET_DB_SAVE_AFTER - ) +def schedule_config_reset(reset_after: int | None): + reset_after = reset_after or settings.LOG_OUTGOING_REQUESTS_RESET_DB_SAVE_AFTER if not reset_after: return diff --git a/log_outgoing_requests/migrations/0006_outgoingrequestslogconfig_reset_db_save_after.py b/log_outgoing_requests/migrations/0006_outgoingrequestslogconfig_reset_db_save_after.py index e75ecae..b7f58a9 100644 --- a/log_outgoing_requests/migrations/0006_outgoingrequestslogconfig_reset_db_save_after.py +++ b/log_outgoing_requests/migrations/0006_outgoingrequestslogconfig_reset_db_save_after.py @@ -1,5 +1,6 @@ -# Generated by Django 3.2.23 on 2024-02-19 11:12 +# Generated by Django 3.2.24 on 2024-02-27 09:32 +import django.core.validators from django.db import migrations, models @@ -15,8 +16,9 @@ class Migration(migrations.Migration): name="reset_db_save_after", field=models.PositiveIntegerField( blank=True, - help_text="If configured, after the config has been updated, reset the database logging after the specified number of minutes. Note: this overrides the LOG_OUTGOING_REQUESTS_RESET_DB_SAVE_AFTER environment variable.", + help_text="If configured, after the config has been updated, reset the database logging after the specified number of minutes. Note: this overrides the LOG_OUTGOING_REQUESTS_RESET_DB_SAVE_AFTER environment variable. Additionally, depending on the broker that is used, if this value is duration is too long the key for the reset task might have expired before that time. So make sure not to set too large a value for the reset.", null=True, + validators=[django.core.validators.MinValueValidator(1)], verbose_name="Reset saving logs in database after", ), ), diff --git a/log_outgoing_requests/models.py b/log_outgoing_requests/models.py index e9b3a32..bdd6a25 100644 --- a/log_outgoing_requests/models.py +++ b/log_outgoing_requests/models.py @@ -210,10 +210,14 @@ class OutgoingRequestsLogConfig(SingletonModel): _("Reset saving logs in database after"), null=True, blank=True, + validators=[MinValueValidator(1)], help_text=_( "If configured, after the config has been updated, reset the database logging " "after the specified number of minutes. Note: this overrides the " - "LOG_OUTGOING_REQUESTS_RESET_DB_SAVE_AFTER environment variable." + "LOG_OUTGOING_REQUESTS_RESET_DB_SAVE_AFTER environment variable. Additionally, " + "depending on the broker that is used, if this value is duration is too long " + "the key for the reset task might have expired before that time. So make sure not to " + "set too large a value for the reset." ), ) @@ -222,7 +226,7 @@ class Meta: def save(self, *args, **kwargs): super().save(*args, **kwargs) - schedule_config_reset(self) + schedule_config_reset(self.reset_db_save_after) @property def save_logs_enabled(self):