From 513d37e9ace8bc5556093f0e17f89dda0ad38901 Mon Sep 17 00:00:00 2001 From: caoqianming Date: Mon, 29 Apr 2024 21:45:35 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20base=20=E5=AE=8C=E6=95=B4=E7=9A=84task?= =?UTF-8?q?=20on=5Ffailure=E6=97=A5=E5=BF=97=E8=AE=B0=E5=BD=95=E5=92=8C?= =?UTF-8?q?=E9=82=AE=E4=BB=B6=E6=8E=A8=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/utils/tasks.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/utils/tasks.py b/apps/utils/tasks.py index ab09128f..556a7afe 100644 --- a/apps/utils/tasks.py +++ b/apps/utils/tasks.py @@ -5,6 +5,7 @@ import logging from django.conf import settings from server.settings import get_sysconfig import importlib +import traceback # 实例化myLogger myLogger = logging.getLogger('log') @@ -27,7 +28,8 @@ class CustomTask(Task): """ def on_failure(self, exc, task_id, args, kwargs, einfo): - detail = '{0!r} failed: {1!r}'.format(task_id, exc) + detail ='Task {0} raised exception: {1!r}\n{2!r}'.format( + task_id, exc, einfo.traceback) myLogger.error(detail) send_mail_task.delay(subject='task_error', message=detail) return super().on_failure(exc, task_id, args, kwargs, einfo)