[Update] 清理task adhoc和history

pull/2230/head
ibuler 2018-12-20 11:05:36 +08:00
parent 7773c30240
commit a1b80f5f0b
2 changed files with 14 additions and 2 deletions

View File

@ -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, \

View File

@ -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))