fix: 修复任务再次执行报500问题 (#9584)

Co-authored-by: Aaron3S <chenyang@fit2cloud.com>
This commit is contained in:
fit2bot
2023-02-16 15:52:21 +08:00
committed by GitHub
parent e84411588a
commit ef33bc211d
6 changed files with 206 additions and 176 deletions

View File

@@ -10,6 +10,7 @@ from django.utils.translation import ugettext as _
from django_celery_beat.models import PeriodicTask
from rest_framework.response import Response
from common.exceptions import JMSException
from common.permissions import IsValidUser
from common.api import LogTailApi, CommonApiMixin
from ops.celery import app
@@ -134,6 +135,11 @@ class CeleryTaskExecutionViewSet(CommonApiMixin, viewsets.ModelViewSet):
execution = get_object_or_404(CeleryTaskExecution, id=form_id)
task = app.tasks.get(execution.name, None)
if not task:
return Response(status=status.HTTP_400_BAD_REQUEST)
t = task.delay(*execution.args, **execution.kwargs)
msg = _("Task {} not found").format(execution.name)
raise JMSException(code='task_not_found_error', detail=msg)
try:
t = task.delay(*execution.args, **execution.kwargs)
except TypeError:
msg = _("Task {} args or kwargs error").format(execution.name)
raise JMSException(code='task_args_error', detail=msg)
return Response(status=status.HTTP_201_CREATED, data={'task_id': t.id})

View File

@@ -62,7 +62,7 @@ class JobViewSet(OrgBulkModelViewSet):
execution = job.create_execution()
execution.creator = self.request.user
execution.save()
task = run_ops_job_execution.delay(execution.id)
task = run_ops_job_execution.delay(str(execution.id))
set_task_to_serializer_data(serializer, task)
@@ -81,7 +81,7 @@ class JobExecutionViewSet(OrgBulkModelViewSet):
instance.job_type = Types[instance.job.type].value
instance.creator = self.request.user
instance.save()
task = run_ops_job_execution.delay(instance.id)
task = run_ops_job_execution.delay(str(instance.id))
set_task_to_serializer_data(serializer, task)
def get_queryset(self):