Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setting for message retention #26

Closed
joshuadavidthomas opened this issue Sep 26, 2023 · 2 comments
Closed

Add setting for message retention #26

joshuadavidthomas opened this issue Sep 26, 2023 · 2 comments

Comments

@joshuadavidthomas
Copy link
Member

Since we are saving the entire email, including any attachments, in a database table, there is potential for the space to grow and grow unless there is some sort of way to clear out old emails.

I think there should be a new setting, something like MESSAGES_RETENTION_SECONDS that takes an int of the number of seconds to keep messages. Then somewhere in the relay loop, either within the runrelay management command, the send_all function, or maybe a new function that is called from within runrelay, that filter's all messages by created_at__lt=timezone.now() - app_settings.MESSAGES_RETENTION_SECONDS and deletes any found.

@jefftriplett
Copy link
Contributor

If the goal is for runrelay to be the primary service, then it might make sense to call a cleanup task/function from there.

Not to overcomplicate it, but I could see someone wanting messages to immediately delete after successfully sent, and I could see people wanting to store the last n-messages for anyone who might send 1000s a day.

@joshuadavidthomas
Copy link
Member Author

joshuadavidthomas commented Sep 26, 2023

# email_relay/conf.py

# keep all (default)
MESSAGES_RETENTION_SECONDS = None
# or
# delete after sending
MESSAGES_RETENTION_SECONDS = 0
# or
# delete after a week
MESSAGES_RETENTION_SECONDS = 604800

Then in the runrelay:

# email_relay/management/commands/runrelay.py
...
send_all()

if app_settings.MESSAGES_RETENTION_SECONDS:
    if app_settings.MESSAGES_RETENTION_SECONDS == 0:
        Messages.objects.sent().delete()
    else:
        Messages.objects.sent_before(timezone.now() - app_settings.MESSAGES_RETENTION_SECONDS).delete()

Then for the n messages, something like:

# email_relay/conf.py

# keep all (default)
MESSAGES_SENT_MAX_KEEP = None
# keep the last 1000
MESSAGES_SENT_MAX_KEEP = 1000

Not in love with that setting name, but I don't hate it so it'll do for now, unless something better comes up.

Then:

# email_relay/runrelay.py
...
send_all()
...

if app_settings.MESSAGES_SENT_MAX_KEEP:
    # do the slicing and dicing here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants