From 98da3bb986d4dc2410eb5de492db4038008b5aaa Mon Sep 17 00:00:00 2001 From: Steven Bal Date: Mon, 19 Feb 2024 11:54:43 +0100 Subject: [PATCH] :sparkles: [#33] Add reset_db_save_after option to config model --- log_outgoing_requests/config_reset.py | 6 +++-- ...ngrequestslogconfig_reset_db_save_after.py | 23 +++++++++++++++++++ log_outgoing_requests/models.py | 12 +++++++++- 3 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 log_outgoing_requests/migrations/0006_outgoingrequestslogconfig_reset_db_save_after.py diff --git a/log_outgoing_requests/config_reset.py b/log_outgoing_requests/config_reset.py index 92ef9bb..c89c52a 100644 --- a/log_outgoing_requests/config_reset.py +++ b/log_outgoing_requests/config_reset.py @@ -4,8 +4,10 @@ from .tasks import reset_config -def schedule_config_reset(): - reset_after = settings.LOG_OUTGOING_REQUESTS_RESET_DB_SAVE_AFTER +def schedule_config_reset(config): + reset_after = ( + config.reset_db_save_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 new file mode 100644 index 0000000..e75ecae --- /dev/null +++ b/log_outgoing_requests/migrations/0006_outgoingrequestslogconfig_reset_db_save_after.py @@ -0,0 +1,23 @@ +# Generated by Django 3.2.23 on 2024-02-19 11:12 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("log_outgoing_requests", "0005_alter_outgoingrequestslog_url"), + ] + + operations = [ + migrations.AddField( + model_name="outgoingrequestslogconfig", + 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.", + null=True, + verbose_name="Reset saving logs in database after", + ), + ), + ] diff --git a/log_outgoing_requests/models.py b/log_outgoing_requests/models.py index 8a5bc66..e9b3a32 100644 --- a/log_outgoing_requests/models.py +++ b/log_outgoing_requests/models.py @@ -206,13 +206,23 @@ class OutgoingRequestsLogConfig(SingletonModel): "If 'Require content length' is not checked, this setting has no effect." ), ) + reset_db_save_after = models.PositiveIntegerField( + _("Reset saving logs in database after"), + null=True, + 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." + ), + ) class Meta: verbose_name = _("Outgoing request log configuration") def save(self, *args, **kwargs): super().save(*args, **kwargs) - schedule_config_reset() + schedule_config_reset(self) @property def save_logs_enabled(self):