mirror of
https://github.com/jumpserver/jumpserver.git
synced 2025-09-13 05:49:07 +00:00
@@ -1,5 +1,6 @@
|
||||
import uuid
|
||||
|
||||
from django.db import transaction
|
||||
from rest_framework import status
|
||||
from rest_framework import viewsets
|
||||
from rest_framework.decorators import action
|
||||
@@ -57,13 +58,17 @@ class AppletHostDeploymentViewSet(viewsets.ModelViewSet):
|
||||
('applets', 'terminal.view_AppletHostDeployment'),
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def start_deploy(instance):
|
||||
task = run_applet_host_deployment.apply_async((instance.id,), task_id=str(instance.id))
|
||||
|
||||
def create(self, request, *args, **kwargs):
|
||||
serializer = self.get_serializer(data=request.data)
|
||||
serializer.is_valid(raise_exception=True)
|
||||
instance = serializer.save()
|
||||
task = run_applet_host_deployment.delay(instance.id)
|
||||
instance.save_task(instance.id)
|
||||
return Response({'task': str(task.id)}, status=201)
|
||||
transaction.on_commit(lambda: self.start_deploy(instance))
|
||||
return Response({'task': str(instance.id)}, status=201)
|
||||
|
||||
@action(methods=['post'], detail=False)
|
||||
def applets(self, request, *args, **kwargs):
|
||||
@@ -79,5 +84,10 @@ class AppletHostDeploymentViewSet(viewsets.ModelViewSet):
|
||||
applet_host_deployment_ids = [str(obj.id) for obj in applet_host_deployments]
|
||||
task_id = str(uuid.uuid4())
|
||||
model.objects.filter(id__in=applet_host_deployment_ids).update(task=task_id)
|
||||
run_applet_host_deployment_install_applet.delay(applet_host_deployment_ids, applet_id)
|
||||
transaction.on_commit(lambda: self.start_install_applet(applet_host_deployment_ids, applet_id, task_id))
|
||||
return Response({'task': task_id}, status=201)
|
||||
|
||||
@staticmethod
|
||||
def start_install_applet(applet_host_deployment_ids, applet_id, task_id):
|
||||
run_applet_host_deployment_install_applet.apply_async((applet_host_deployment_ids, applet_id),
|
||||
task_id=str(task_id))
|
||||
|
Reference in New Issue
Block a user