mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-20 02:51:27 +00:00
perf: 修改日志清理
This commit is contained in:
@@ -1,24 +1,19 @@
|
||||
# coding: utf-8
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
from celery import shared_task
|
||||
from celery.exceptions import SoftTimeLimitExceeded
|
||||
from django.conf import settings
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from common.utils import get_logger, get_object_or_none, get_log_keep_day
|
||||
from common.utils import get_logger, get_object_or_none
|
||||
from orgs.utils import tmp_to_org
|
||||
from .celery.decorator import (
|
||||
register_as_period_task, after_app_shutdown_clean_periodic,
|
||||
after_app_ready_start
|
||||
register_as_period_task, after_app_ready_start
|
||||
)
|
||||
from .celery.utils import (
|
||||
create_or_update_celery_periodic_tasks, get_celery_periodic_task,
|
||||
disable_celery_periodic_task, delete_celery_periodic_task
|
||||
)
|
||||
from .models import CeleryTaskExecution, Job, JobExecution
|
||||
from .models import Job, JobExecution
|
||||
from .notifications import ServerPerformanceCheckUtil
|
||||
|
||||
logger = get_logger(__file__)
|
||||
@@ -55,25 +50,6 @@ def run_ops_job_execution(execution_id, **kwargs):
|
||||
logger.error("Start adhoc execution error: {}".format(e))
|
||||
|
||||
|
||||
@shared_task(verbose_name=_('Periodic clear celery tasks'))
|
||||
@after_app_shutdown_clean_periodic
|
||||
@register_as_period_task(interval=3600 * 24, description=_("Clean celery log period"))
|
||||
def clean_celery_tasks_period():
|
||||
logger.debug("Start clean celery task history")
|
||||
expire_days = get_log_keep_day('TASK_LOG_KEEP_DAYS')
|
||||
days_ago = timezone.now() - timezone.timedelta(days=expire_days)
|
||||
tasks = CeleryTaskExecution.objects.filter(date_start__lt=days_ago)
|
||||
tasks.delete()
|
||||
tasks = CeleryTaskExecution.objects.filter(date_start__isnull=True)
|
||||
tasks.delete()
|
||||
command = "find %s -mtime +%s -name '*.log' -type f -exec rm -f {} \\;" % (
|
||||
settings.CELERY_LOG_DIR, expire_days
|
||||
)
|
||||
subprocess.call(command, shell=True)
|
||||
command = "echo > {}".format(os.path.join(settings.LOG_DIR, 'celery.log'))
|
||||
subprocess.call(command, shell=True)
|
||||
|
||||
|
||||
@shared_task(verbose_name=_('Clear celery periodic tasks'))
|
||||
@after_app_ready_start
|
||||
def clean_celery_periodic_tasks():
|
||||
|
Reference in New Issue
Block a user