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

Added a settings variable to allow configurable time periods for notification deletion #2547

Merged
merged 3 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions care/facility/tasks/cleanup.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
from datetime import timedelta

from celery import shared_task
from django.conf import settings
from django.utils import timezone

from care.facility.models.notification import Notification


@shared_task
def delete_old_notifications():
ninety_days_ago = timezone.now() - timedelta(days=90)
Notification.objects.filter(created_date__lte=ninety_days_ago).delete()
retention_days = settings.NOTIFICATION_RETENTION_DAYS

threshold_date = timezone.now() - timedelta(days=retention_days)
Notification.objects.filter(created_date__lte=threshold_date).delete()
7 changes: 5 additions & 2 deletions care/facility/tests/test_delete_older_notifications_task.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from datetime import timedelta

from django.conf import settings
from django.test import TestCase
from django.utils import timezone
from freezegun import freeze_time
Expand All @@ -10,8 +11,10 @@

class DeleteOldNotificationsTest(TestCase):
def test_delete_old_notifications(self):
# notifications created 90 days ago
with freeze_time(timezone.now() - timedelta(days=90)):
retention_days = settings.NOTIFICATION_RETENTION_DAYS

# notifications created at the threshold of retention
with freeze_time(timezone.now() - timedelta(days=retention_days)):
notification1 = Notification.objects.create()
notification2 = Notification.objects.create()

Expand Down
1 change: 1 addition & 0 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@
"VAPID_PRIVATE_KEY", default="7mf3OFreFsgFF4jd8A71ZGdVaj8kpJdOto4cFbfAS-s"
)
SEND_SMS_NOTIFICATION = False
NOTIFICATION_RETENTION_DAYS = env.int("NOTIFICATION_RETENTION_DAYS", default=30)

# Cloud and Buckets
# ------------------------------------------------------------------------------
Expand Down
Loading