* [Bugfix] 修复两个配置文件冲突问题

* [Update] Docker中不再提供配置文件
This commit is contained in:
老广
2019-01-08 11:15:09 +08:00
committed by GitHub
parent 0e1d3f93ff
commit 49a166552e
5 changed files with 45 additions and 20 deletions

View File

@@ -1,9 +1,12 @@
# coding: utf-8
import os
from celery import shared_task, subtask
from django.utils import timezone
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
from .models import Task, CommandExecution, CeleryTask
logger = get_logger(__file__)
@@ -48,6 +51,24 @@ def clean_tasks_adhoc_period():
ad.delete()
@shared_task
@register_as_period_task(interval=3600*24)
@after_app_shutdown_clean
def clean_celery_tasks_period():
logger.debug("Start clean celery task history")
one_month_ago = timezone.now() - timezone.timedelta(days=30)
tasks = CeleryTask.objects.filter(date_start__lt=one_month_ago)
for task in tasks:
if os.path.isfile(task.full_log_path):
try:
os.remove(task.full_log_path)
except (FileNotFoundError, PermissionError):
pass
task.delete()
tasks = CeleryTask.objects.filter(date_start__isnull=True)
tasks.delete()
@shared_task
def hello(name, callback=None):
print("Hello {}".format(name))