You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

14 lines
450 B

  1. from datetime import timedelta
  2. from django.core.management.base import BaseCommand
  3. from django.utils import timezone
  4. from hc.api.models import Check
  5. class Command(BaseCommand):
  6. help = 'Prune anonymous checks older than 2 hours'
  7. def handle(self, *args, **options):
  8. cutoff = timezone.now() - timedelta(hours=2)
  9. n, _ = Check.objects.filter(user=None, created__lt=cutoff).delete()
  10. return "Done! Pruned %d checks." % n