21ca43248a
Co-Authored-By: Claude Code <noreply@anthropic.com>
20 lines
760 B
Python
20 lines
760 B
Python
from datetime import timedelta
|
|
|
|
from django.core.management.base import BaseCommand
|
|
from django.utils import timezone
|
|
from tracker.models import RawBatch
|
|
|
|
|
|
class Command(BaseCommand):
|
|
# 生产调度:1Panel 计划任务每日执行(与 refresh_stats 同款)
|
|
# docker exec <web容器> python manage.py cleanup_raw --days 30
|
|
help = "清理 N 天前的原始上报批次(raw_batch 默认保留 30 天)"
|
|
|
|
def add_arguments(self, parser):
|
|
parser.add_argument("--days", type=int, default=30)
|
|
|
|
def handle(self, *args, **opts):
|
|
cutoff = timezone.now() - timedelta(days=opts["days"])
|
|
deleted, _ = RawBatch.objects.filter(received_at__lt=cutoff).delete()
|
|
self.stdout.write(f"deleted {deleted} raw batches")
|