healthchecks/hc/api/management/commands/prunetokenbucket.py
2019-05-15 14:27:50 +03:00

18 lines
493 B
Python

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