fix: 修复多个 AdHocExecution 在一个 celery task 执行时日志错误

This commit is contained in:
xinwen
2020-12-29 21:05:18 +08:00
parent 3188692691
commit f5fd40978e
14 changed files with 160 additions and 25 deletions

View File

@@ -15,10 +15,14 @@ from common.api import LogTailApi
from ..models import CeleryTask
from ..serializers import CeleryResultSerializer, CeleryPeriodTaskSerializer
from ..celery.utils import get_celery_task_log_path
from ..ansible.utils import get_ansible_task_log_path
from common.mixins.api import CommonApiMixin
__all__ = ['CeleryTaskLogApi', 'CeleryResultApi', 'CeleryPeriodTaskViewSet']
__all__ = [
'CeleryTaskLogApi', 'CeleryResultApi', 'CeleryPeriodTaskViewSet',
'AnsibleTaskLogApi',
]
class CeleryTaskLogApi(LogTailApi):
@@ -57,6 +61,21 @@ class CeleryTaskLogApi(LogTailApi):
return _('Waiting task start')
class AnsibleTaskLogApi(LogTailApi):
permission_classes = (IsValidUser,)
def get_log_path(self):
new_path = get_ansible_task_log_path(self.kwargs.get('pk'))
if new_path and os.path.isfile(new_path):
return new_path
def get_no_file_message(self, request):
if self.mark == 'undefined':
return '.'
else:
return _('Waiting task start')
class CeleryResultApi(generics.RetrieveAPIView):
permission_classes = (IsValidUser,)
serializer_class = CeleryResultSerializer