19 lines
530 B
Python
19 lines
530 B
Python
# Create your tasks here
|
|
from __future__ import absolute_import, unicode_literals
|
|
from datetime import timedelta
|
|
from apps.monitor.models import DrfRequestLog
|
|
from apps.utils.tasks import CustomTask
|
|
from celery import shared_task
|
|
from django.utils import timezone
|
|
|
|
|
|
@shared_task(base=CustomTask)
|
|
def clear_drf_log():
|
|
"""清除7天前的日志记录
|
|
|
|
清除7天前的日志记录
|
|
"""
|
|
now = timezone.now()
|
|
days7_ago = now - timedelta(days=7)
|
|
DrfRequestLog.objects.filter(create_time__lte=days7_ago).delete()
|