mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-06-01 19:35:23 +00:00
* [Update] 修改config * [Update] 移动存储设置到到terminal中 * [Update] 修改permission 查看 * [Update] pre merge * [Update] 录像存储 * [Update] 命令存储 * [Update] 添加存储测试可连接性 * [Update] 修改 meta 值的 key 为大写 * [Update] 修改 Terminal 相关 Storage 配置 * [Update] 删除之前获取录像/命令存储的代码 * [Update] 修改导入失败 * [Update] 迁移文件添加default存储 * [Update] 删除之前代码,添加help_text信息 * [Update] 删除之前代码 * [Update] 删除之前代码 * [Update] 抽象命令/录像存储 APIView * [Update] 抽象命令/录像存储 APIView 1 * [Update] 抽象命令/录像存储 DictField * [Update] 抽象命令/录像存储列表页面 * [Update] 修复CustomDictField的bug * [Update] RemoteApp 页面添加 hidden * [Update] 用户页面添加用户关联授权 * [Update] 修改存储测试可连接性 target * [Update] 修改配置 * [Update] 修改存储前端 Form 渲染逻辑 * [Update] 修改存储细节 * [Update] 统一存储类型到 const 文件 * [Update] 修改迁移文件及Model,创建默认存储 * [Update] 修改迁移文件及Model初始化默认数据 * [Update] 修改迁移文件 * [Update] 修改迁移文件 * [Update] 修改迁移文件 * [Update] 修改迁移文件 * [Update] 修改迁移文件 * [Update] 修改迁移文件 * [Update] 修改迁移文件 * [Update] 限制删除默认存储配置,只允许创建扩展的存储类型 * [Update] 修改ip字段长度 * [Update] 修改ip字段长度 * [Update] 修改一些css * [Update] 修改关联 * [Update] 添加操作日志定时清理 * [Update] 修改记录syslog的instance encoder * [Update] 忽略登录产生的操作日志 * [Update] 限制更新存储时不覆盖原有AK SK 等字段 * [Update] 修改迁移文件添加comment字段 * [Update] 修改迁移文件 * [Update] 添加 comment 字段 * [Update] 修改默认存储no -> null * [Update] 修改细节 * [Update] 更新翻译(存储配置 * [Update] 修改定时任务注册,修改系统用户资产、节点关系api * [Update] 添加监控磁盘任务 * [Update] 修改session * [Update] 拆分serializer * [Update] 还原setting原来的manager
79 lines
2.3 KiB
Python
79 lines
2.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
#
|
|
|
|
import os
|
|
import re
|
|
|
|
from django.utils.translation import ugettext as _
|
|
from rest_framework import viewsets
|
|
from celery.result import AsyncResult
|
|
from rest_framework import generics
|
|
from django_celery_beat.models import PeriodicTask
|
|
|
|
from common.permissions import IsValidUser, IsSuperUser
|
|
from common.api import LogTailApi
|
|
from ..models import CeleryTask
|
|
from ..serializers import CeleryResultSerializer, CeleryPeriodTaskSerializer
|
|
from ..celery.utils import get_celery_task_log_path
|
|
from common.mixins.api import CommonApiMixin
|
|
|
|
|
|
__all__ = ['CeleryTaskLogApi', 'CeleryResultApi', 'CeleryPeriodTaskViewSet']
|
|
|
|
|
|
class CeleryTaskLogApi(LogTailApi):
|
|
permission_classes = (IsValidUser,)
|
|
task = None
|
|
task_id = ''
|
|
pattern = re.compile(r'Task .* succeeded in \d+\.\d+s.*')
|
|
|
|
def get(self, request, *args, **kwargs):
|
|
self.task_id = str(kwargs.get('pk'))
|
|
self.task = AsyncResult(self.task_id)
|
|
return super().get(request, *args, **kwargs)
|
|
|
|
def filter_line(self, line):
|
|
if self.pattern.match(line):
|
|
line = self.pattern.sub(line, '')
|
|
return line
|
|
|
|
def get_log_path(self):
|
|
new_path = get_celery_task_log_path(self.task_id)
|
|
if new_path and os.path.isfile(new_path):
|
|
return new_path
|
|
try:
|
|
task = CeleryTask.objects.get(id=self.task_id)
|
|
except CeleryTask.DoesNotExist:
|
|
return None
|
|
return task.full_log_path
|
|
|
|
def is_file_finish_write(self):
|
|
return self.task.ready()
|
|
|
|
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
|
|
|
|
def get_object(self):
|
|
pk = self.kwargs.get('pk')
|
|
return AsyncResult(pk)
|
|
|
|
|
|
class CeleryPeriodTaskViewSet(CommonApiMixin, viewsets.ModelViewSet):
|
|
queryset = PeriodicTask.objects.all()
|
|
serializer_class = CeleryPeriodTaskSerializer
|
|
permission_classes = (IsSuperUser,)
|
|
http_method_names = ('get', 'head', 'options', 'patch')
|
|
|
|
def get_queryset(self):
|
|
queryset = super().get_queryset()
|
|
queryset = queryset.exclude(description='')
|
|
return queryset
|