factory/apps/third/tasks.py

19 lines
507 B
Python

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