mirror of https://github.com/jumpserver/jumpserver
perf: 优化推送部署任务,事务提交后再执行
parent
5cbbf9e737
commit
b91db8c146
|
@ -56,14 +56,17 @@ class AppletHostDeploymentViewSet(viewsets.ModelViewSet):
|
||||||
('applets', 'terminal.view_AppletHostDeployment'),
|
('applets', 'terminal.view_AppletHostDeployment'),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def start_deploy(instance):
|
||||||
|
task = run_applet_host_deployment.apply_async((instance.id,), task_id=str(instance.id))
|
||||||
|
instance.save_task(task.id)
|
||||||
|
|
||||||
def create(self, request, *args, **kwargs):
|
def create(self, request, *args, **kwargs):
|
||||||
serializer = self.get_serializer(data=request.data)
|
serializer = self.get_serializer(data=request.data)
|
||||||
serializer.is_valid(raise_exception=True)
|
serializer.is_valid(raise_exception=True)
|
||||||
with transaction.atomic():
|
|
||||||
instance = serializer.save()
|
instance = serializer.save()
|
||||||
task = run_applet_host_deployment.delay(instance.id)
|
transaction.on_commit(lambda: self.start_deploy(instance))
|
||||||
instance.save_task(task.id)
|
return Response({'task': str(instance.id)}, status=201)
|
||||||
return Response({'task': str(task.id)}, status=201)
|
|
||||||
|
|
||||||
@action(methods=['post'], detail=False)
|
@action(methods=['post'], detail=False)
|
||||||
def applets(self, request, *args, **kwargs):
|
def applets(self, request, *args, **kwargs):
|
||||||
|
|
Loading…
Reference in New Issue