mirror of https://github.com/jumpserver/jumpserver
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
34 lines
911 B
34 lines
911 B
# -*- 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
|
|
from .models import UserLoginLog, OperateLog
|
|
|
|
|
|
@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()
|
|
|
|
|
|
@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()
|