From 913c0d140d5fa000c732f2941bb306bb04897d71 Mon Sep 17 00:00:00 2001 From: Bai Date: Thu, 18 Apr 2024 21:18:31 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20Celery=20Execution?= =?UTF-8?q?=20=E4=BB=BB=E5=8A=A1=E4=BF=9D=E5=AD=98=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=20View=20=E4=BA=8B=E5=8A=A1=E5=9B=9E?= =?UTF-8?q?=E6=BB=9A=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=88=E9=A6=96=E6=AC=A1?= =?UTF-8?q?=E7=99=BB=E5=BD=95=E7=94=A8=E6=88=B7=E4=BF=AE=E6=94=B9=E5=AF=86?= =?UTF-8?q?=E7=A0=81=E5=A4=B1=E8=B4=A5=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/ops/signal_handlers.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/apps/ops/signal_handlers.py b/apps/ops/signal_handlers.py index 6fb2ced2d..ad3428100 100644 --- a/apps/ops/signal_handlers.py +++ b/apps/ops/signal_handlers.py @@ -134,9 +134,10 @@ def task_sent_handler(headers=None, body=None, **kwargs): args, kwargs, __ = body try: - args = list(args) + args = json.loads(json.dumps(list(args), cls=JSONEncoder)) kwargs = json.loads(json.dumps(kwargs, cls=JSONEncoder)) except Exception as e: + logger.error('Parse task args or kwargs error (Need handle): {}'.format(e)) args = [] kwargs = {} @@ -151,11 +152,13 @@ def task_sent_handler(headers=None, body=None, **kwargs): request = get_current_request() if request and request.user.is_authenticated: data['creator'] = request.user - try: - CeleryTaskExecution.objects.create(**data) - except Exception as e: - logger.error(e) - CeleryTask.objects.filter(name=task).update(date_last_publish=timezone.now()) + + with transaction.atomic(): + try: + CeleryTaskExecution.objects.create(**data) + except Exception as e: + logger.error('Create celery task execution error: {}'.format(e)) + CeleryTask.objects.filter(name=task).update(date_last_publish=timezone.now()) @receiver(django_ready)