From 1eb1f7123290acfd05d502f770f9c82ac7b9fa16 Mon Sep 17 00:00:00 2001 From: Keannu Bernasol Date: Sun, 1 Oct 2023 16:50:01 +0800 Subject: [PATCH] Improved pruning command logging --- .../management/commands/clean_old_entries.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/stude/accounts/management/commands/clean_old_entries.py b/stude/accounts/management/commands/clean_old_entries.py index 40bd156..c7f4f80 100644 --- a/stude/accounts/management/commands/clean_old_entries.py +++ b/stude/accounts/management/commands/clean_old_entries.py @@ -3,6 +3,9 @@ from django.utils import timezone from django.contrib.gis.geos import Point from study_groups.models import StudyGroup from student_status.models import StudentStatus +import logging + +logger = logging.getLogger(__name__) class Command(BaseCommand): @@ -15,8 +18,15 @@ class Command(BaseCommand): # Get the time 8 hours ago time_threshold = now - timezone.timedelta(hours=8) - # Delete StudyGroup entries older than 8 hours - StudyGroup.objects.filter(timestamp__lt=time_threshold).delete() + # Get StudyGroup entries older than 8 hours + old_groups = StudyGroup.objects.filter(timestamp__lt=time_threshold) + + # Log the old groups + for group in old_groups: + logger.info(f'Deleting StudyGroup: {group}') + + # Delete the old groups + old_groups.delete() # Get StudentStatus entries older than 8 hours old_statuses = StudentStatus.objects.filter( @@ -24,6 +34,7 @@ class Command(BaseCommand): # Set the fields of the old statuses to the required values for status in old_statuses: + logger.info(f'Resetting StudentStatus: {status}') status.location = Point(0, 0) status.subject = None status.landmark = None