tasks.py 695 B

12345678910111213141516171819
  1. from datetime import timedelta
  2. from django.utils.timezone import now
  3. from django.conf import settings
  4. from celery import shared_task
  5. from .models import TransactionEvent, TransactionGroup, Span
  6. @shared_task
  7. def cleanup_old_transaction_events():
  8. """Delete older events and associated data"""
  9. days = settings.GLITCHTIP_MAX_EVENT_LIFE_DAYS
  10. qs = TransactionEvent.objects.filter(created__lt=now() - timedelta(days=days))
  11. # Fast bulk delete - see https://code.djangoproject.com/ticket/9519
  12. qs._raw_delete(qs.db)
  13. qs = Span.objects.filter(created__lt=now() - timedelta(days=days))
  14. qs._raw_delete(qs.db)
  15. TransactionGroup.objects.filter(transactionevent=None).delete()