Skip to content

Commit

Permalink
Added a settings variable to allow configurable time periods for noti…
Browse files Browse the repository at this point in the history
…fication deletion (#2547)

Added NOTIFICATION_RETENTION_DAYS settings variable to allow configurable time period with default of 30 days
  • Loading branch information
arilloid authored Nov 4, 2024
1 parent 39c7aa4 commit 8d5e701
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
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 @@ -530,6 +530,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

0 comments on commit 8d5e701

Please sign in to comment.