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.

17 lines
493 B

  1. from datetime import timedelta
  2. from django.core.management.base import BaseCommand
  3. from django.utils.timezone import now
  4. from hc.api.models import TokenBucket
  5. class Command(BaseCommand):
  6. help = "Prune pings based on limits in user profiles"
  7. def handle(self, *args, **options):
  8. day_ago = now() - timedelta(days=1)
  9. q = TokenBucket.objects.filter(updated__lt=day_ago)
  10. n_pruned, _ = q.delete()
  11. return "Done! Pruned %d token bucket entries" % n_pruned