feat: 批量命令api

This commit is contained in:
Aaron3S
2022-12-23 18:23:04 +08:00
parent 8de2ffe5f4
commit e32d51253a
3 changed files with 22 additions and 2 deletions

View File

@@ -5,11 +5,12 @@ from rest_framework.response import Response
from ops.models import Job, JobExecution
from ops.serializers.job import JobSerializer, JobExecutionSerializer
__all__ = ['JobViewSet', 'JobExecutionViewSet', 'JobRunVariableHelpAPIView', 'JobAssetDetail', ]
__all__ = ['JobViewSet', 'JobExecutionViewSet', 'JobRunVariableHelpAPIView', 'JobAssetDetail', 'JobExecutionTaskDetail']
from ops.tasks import run_ops_job_execution
from ops.variables import JMS_JOB_VARIABLE_HELP
from orgs.mixins.api import OrgBulkModelViewSet
from orgs.utils import tmp_to_org, get_current_org_id, get_current_org
def set_task_to_serializer_data(serializer, task):
@@ -93,3 +94,20 @@ class JobAssetDetail(APIView):
if execution_id:
execution = get_object_or_404(JobExecution, id=execution_id)
return Response(data=execution.assent_result_detail)
class JobExecutionTaskDetail(APIView):
rbac_perms = ()
permission_classes = ()
def get(self, request, **kwargs):
org = get_current_org()
task_id = request.query_params.get('task_id')
if task_id:
with tmp_to_org(org):
execution = get_object_or_404(JobExecution, task_id=task_id)
return Response(data={
'is_finished': execution.is_finished,
'is_success': execution.is_success,
'time_cost': execution.time_cost,
})