mirror of
https://github.com/lemeow125/StudE-Backend.git
synced 2024-11-17 06:19:24 +08:00
Prune groups and statuses older than 4 hours from 8 hours and improved student status filtering for pruning
This commit is contained in:
parent
a58142030d
commit
c140e7fc6a
1 changed files with 6 additions and 4 deletions
|
@ -16,25 +16,27 @@ class Command(BaseCommand):
|
||||||
now = timezone.now()
|
now = timezone.now()
|
||||||
|
|
||||||
# Get the time 8 hours ago
|
# 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
|
# Get StudyGroup entries older than 8 hours
|
||||||
old_groups = StudyGroup.objects.filter(timestamp__lt=time_threshold)
|
old_groups = StudyGroup.objects.filter(timestamp__lt=time_threshold)
|
||||||
|
|
||||||
# Log the old groups
|
# Log the old groups
|
||||||
for group in 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
|
# Delete the old groups
|
||||||
old_groups.delete()
|
old_groups.delete()
|
||||||
|
|
||||||
# Get StudentStatus entries older than 8 hours
|
# Get StudentStatus entries older than 8 hours
|
||||||
old_statuses = StudentStatus.objects.filter(
|
old_statuses = StudentStatus.objects.filter(active=True).filter(
|
||||||
timestamp__lt=time_threshold)
|
timestamp__lt=time_threshold)
|
||||||
|
|
||||||
# Set the fields of the old statuses to the required values
|
# Set the fields of the old statuses to the required values
|
||||||
for status in old_statuses:
|
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.active = False
|
||||||
status.location = Point(0, 0)
|
status.location = Point(0, 0)
|
||||||
status.subject = None
|
status.subject = None
|
||||||
|
|
Loading…
Reference in a new issue