From b91db8c146dd7b53231f7239f7c963a0b20924a2 Mon Sep 17 00:00:00 2001 From: ibuler Date: Thu, 14 Sep 2023 18:17:22 +0800 Subject: [PATCH] =?UTF-8?q?perf:=20=E4=BC=98=E5=8C=96=E6=8E=A8=E9=80=81?= =?UTF-8?q?=E9=83=A8=E7=BD=B2=E4=BB=BB=E5=8A=A1=EF=BC=8C=E4=BA=8B=E5=8A=A1?= =?UTF-8?q?=E6=8F=90=E4=BA=A4=E5=90=8E=E5=86=8D=E6=89=A7=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/terminal/api/applet/host.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/apps/terminal/api/applet/host.py b/apps/terminal/api/applet/host.py index 6b06ee44e..c348b75e3 100644 --- a/apps/terminal/api/applet/host.py +++ b/apps/terminal/api/applet/host.py @@ -56,14 +56,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)) + instance.save_task(task.id) + def create(self, request, *args, **kwargs): serializer = self.get_serializer(data=request.data) serializer.is_valid(raise_exception=True) - with transaction.atomic(): - instance = serializer.save() - task = run_applet_host_deployment.delay(instance.id) - instance.save_task(task.id) - return Response({'task': str(task.id)}, status=201) + instance = serializer.save() + 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):