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 (
|
|
|
|
register_as_period_task, after_app_shutdown_clean_periodic
|
|
|
|
)
|
2019-12-05 07:09:25 +00:00
|
|
|
from .models import UserLoginLog, OperateLog
|
2020-10-26 06:13:20 +00:00
|
|
|
from common.utils import get_log_keep_day
|
2019-03-04 03:36:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
@shared_task
|
2020-10-26 06:13:20 +00:00
|
|
|
@after_app_shutdown_clean_periodic
|
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
|
|
|
@shared_task
|
2020-10-26 06:13:20 +00:00
|
|
|
@after_app_shutdown_clean_periodic
|
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()
|
|
|
|
|
|
|
|
|
|
|
|
@shared_task
|
|
|
|
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)
|
|
|
|
OperateLog.objects.filter(datetime__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()
|