Revert "perf: 修复事务中任务执行"

This reverts commit cdbe5d31e9.
This commit is contained in:
老广
2023-09-21 15:39:46 +08:00
committed by Eric_Lee
parent 0397bdeb46
commit 4cb499953c
7 changed files with 24 additions and 13 deletions

View File

@@ -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))