mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-18 16:39:28 +00:00
[Update] 清理task adhoc和history
This commit is contained in:
@@ -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))
|
||||
|
Reference in New Issue
Block a user