From c140e7fc6a50438097b804a59c3d6e4b3e894de2 Mon Sep 17 00:00:00 2001 From: Keannu Bernasol Date: Tue, 17 Oct 2023 21:39:47 +0800 Subject: [PATCH] Prune groups and statuses older than 4 hours from 8 hours and improved student status filtering for pruning --- .../accounts/management/commands/clean_old_entries.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/stude/accounts/management/commands/clean_old_entries.py b/stude/accounts/management/commands/clean_old_entries.py index 2ed9397..1beb02a 100644 --- a/stude/accounts/management/commands/clean_old_entries.py +++ b/stude/accounts/management/commands/clean_old_entries.py @@ -16,25 +16,27 @@ class Command(BaseCommand): now = timezone.now() # Get the time 8 hours ago - time_threshold = now - timezone.timedelta(hours=8) + time_threshold = now - timezone.timedelta(hours=4) # 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}') + self.stdout.write(self.style.SUCCESS( + f'Deleting StudyGroup: {group}')) # Delete the old groups old_groups.delete() # Get StudentStatus entries older than 8 hours - old_statuses = StudentStatus.objects.filter( + old_statuses = StudentStatus.objects.filter(active=True).filter( timestamp__lt=time_threshold) # Set the fields of the old statuses to the required values for status in old_statuses: - logger.info(f'Resetting StudentStatus: {status}') + self.stdout.write(self.style.SUCCESS( + f'Resetting StudentStatus: {status}')) status.active = False status.location = Point(0, 0) status.subject = None