mirror of
https://github.com/lemeow125/StudE-Backend.git
synced 2024-11-17 06:19:24 +08:00
Improved pruning command logging
This commit is contained in:
parent
13ba0cb12a
commit
1eb1f71232
1 changed files with 13 additions and 2 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue