Skip to content

Commit

Permalink
✨ [#33] Add reset_db_save_after option to config model
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenbal committed Feb 19, 2024
1 parent 704b1ae commit 98da3bb
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
6 changes: 4 additions & 2 deletions log_outgoing_requests/config_reset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -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",
),
),
]
12 changes: 11 additions & 1 deletion log_outgoing_requests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 98da3bb

Please sign in to comment.