mirror of https://github.com/jumpserver/jumpserver
[Update] 清理task adhoc和history
parent
7773c30240
commit
a1b80f5f0b
|
@ -4,8 +4,6 @@ import re
|
|||
import os
|
||||
|
||||
from celery import shared_task
|
||||
from ops.celery import app as celery_app
|
||||
from django.core.cache import cache
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
from common.utils import capacity_convert, \
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
from celery import shared_task, subtask
|
||||
|
||||
from common.utils import get_logger, get_object_or_none
|
||||
from .celery.utils import register_as_period_task, after_app_shutdown_clean
|
||||
from .models import Task, CommandExecution
|
||||
|
||||
logger = get_logger(__file__)
|
||||
|
@ -34,6 +35,19 @@ def run_command_execution(cid, **kwargs):
|
|||
return execution.run()
|
||||
|
||||
|
||||
@shared_task
|
||||
@register_as_period_task(interval=3600*24)
|
||||
@after_app_shutdown_clean
|
||||
def clean_tasks_adhoc_period():
|
||||
logger.debug("Start clean task adhoc and run history")
|
||||
tasks = Task.objects.all()
|
||||
for task in tasks:
|
||||
adhoc = task.adhoc.all().order_by('-date_created')[5:]
|
||||
for ad in adhoc:
|
||||
ad.history.all().delete()
|
||||
ad.delete()
|
||||
|
||||
|
||||
@shared_task
|
||||
def hello(name, callback=None):
|
||||
print("Hello {}".format(name))
|
||||
|
|
Loading…
Reference in New Issue