2019-03-04 03:36:10 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
import datetime
|
|
|
|
from django.utils import timezone
|
|
|
|
from django.conf import settings
|
|
|
|
from celery import shared_task
|
|
|
|
|
|
|
|
from ops.celery.decorator import register_as_period_task
|
2019-12-05 07:09:25 +00:00
|
|
|
from .models import UserLoginLog, OperateLog
|
2019-03-04 03:36:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
@register_as_period_task(interval=3600*24)
|
|
|
|
@shared_task
|
|
|
|
def clean_login_log_period():
|
|
|
|
now = timezone.now()
|
|
|
|
try:
|
|
|
|
days = int(settings.LOGIN_LOG_KEEP_DAYS)
|
|
|
|
except ValueError:
|
|
|
|
days = 90
|
|
|
|
expired_day = now - datetime.timedelta(days=days)
|
|
|
|
UserLoginLog.objects.filter(datetime__lt=expired_day).delete()
|
2019-11-05 10:46:29 +00:00
|
|
|
|
|
|
|
|
2019-12-05 07:09:25 +00:00
|
|
|
@register_as_period_task(interval=3600*24)
|
|
|
|
@shared_task
|
|
|
|
def clean_operation_log_period():
|
|
|
|
now = timezone.now()
|
|
|
|
try:
|
|
|
|
days = int(settings.LOGIN_LOG_KEEP_DAYS)
|
|
|
|
except ValueError:
|
|
|
|
days = 90
|
|
|
|
expired_day = now - datetime.timedelta(days=days)
|
|
|
|
OperateLog.objects.filter(datetime__lt=expired_day).delete()
|