2019-03-04 03:36:10 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
import datetime
|
|
|
|
from django.utils import timezone
|
|
|
|
from celery import shared_task
|
|
|
|
|
2020-10-26 06:13:20 +00:00
|
|
|
from ops.celery.decorator import (
|
2021-09-09 06:00:50 +00:00
|
|
|
register_as_period_task
|
2020-10-26 06:13:20 +00:00
|
|
|
)
|
2022-04-19 09:06:05 +00:00
|
|
|
from .models import UserLoginLog, OperateLog, FTPLog
|
2020-10-26 06:13:20 +00:00
|
|
|
from common.utils import get_log_keep_day
|
2019-03-04 03:36:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
def clean_login_log_period():
|
|
|
|
now = timezone.now()
|
2020-10-26 06:13:20 +00:00
|
|
|
days = get_log_keep_day('LOGIN_LOG_KEEP_DAYS')
|
2019-03-04 03:36:10 +00:00
|
|
|
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
|
|
|
def clean_operation_log_period():
|
|
|
|
now = timezone.now()
|
2020-10-26 06:13:20 +00:00
|
|
|
days = get_log_keep_day('OPERATE_LOG_KEEP_DAYS')
|
|
|
|
expired_day = now - datetime.timedelta(days=days)
|
|
|
|
OperateLog.objects.filter(datetime__lt=expired_day).delete()
|
|
|
|
|
|
|
|
|
|
|
|
def clean_ftp_log_period():
|
|
|
|
now = timezone.now()
|
|
|
|
days = get_log_keep_day('FTP_LOG_KEEP_DAYS')
|
2019-12-05 07:09:25 +00:00
|
|
|
expired_day = now - datetime.timedelta(days=days)
|
2022-07-19 09:34:55 +00:00
|
|
|
FTPLog.objects.filter(date_start__lt=expired_day).delete()
|
2020-10-26 06:13:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
@register_as_period_task(interval=3600*24)
|
|
|
|
@shared_task
|
|
|
|
def clean_audits_log_period():
|
2021-01-08 10:33:20 +00:00
|
|
|
clean_login_log_period()
|
2020-10-26 06:13:20 +00:00
|
|
|
clean_operation_log_period()
|
|
|
|
clean_ftp_log_period()
|