From 3c91e23cecf469109158a140bed9a22b066bbe0e Mon Sep 17 00:00:00 2001 From: caoqianming Date: Thu, 23 Mar 2023 13:48:13 +0800 Subject: [PATCH] =?UTF-8?q?refector:=20=E6=AD=A3=E5=BC=8F=E7=8E=AF?= =?UTF-8?q?=E5=A2=83500=E6=89=8D=E5=8F=91=E9=82=AE=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/utils/tasks.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/apps/utils/tasks.py b/apps/utils/tasks.py index c6e218a3..928f6558 100644 --- a/apps/utils/tasks.py +++ b/apps/utils/tasks.py @@ -10,11 +10,12 @@ myLogger = logging.getLogger('log') @shared_task def send_mail_task(**args): - from django.core.mail import send_mail - args['subject'] = args.get('subject', '{}:{}_{}_500'.format(settings.SYS_NAME, settings.SYS_VERSION, settings.PROJECT_NAME)) - args['from_email'] = args.get('from_email', settings.EMAIL_HOST_USER) - args['recipient_list'] = args.get('recipient_list', [settings.EMAIL_HOST_USER]) - send_mail(**args) + if settings.DEBUG is False: + from django.core.mail import send_mail + args['subject'] = args.get('subject', '{}:{}_{}_500'.format(settings.SYS_NAME, settings.SYS_VERSION, settings.PROJECT_NAME)) + args['from_email'] = args.get('from_email', settings.EMAIL_HOST_USER) + args['recipient_list'] = args.get('recipient_list', [settings.EMAIL_HOST_USER]) + send_mail(**args) class CustomTask(Task): @@ -23,7 +24,8 @@ class CustomTask(Task): """ def on_failure(self, exc, task_id, args, kwargs, einfo): - detail = '{0!r} failed: {1!r}'.format(task_id, exc) - myLogger.error(detail) - send_mail_task.delay(subject='{}:{}_{}_task_error'.format(settings.SYS_NAME, settings.SYS_VERSION, settings.PROJECT_NAME), message=detail) - return super().on_failure(exc, task_id, args, kwargs, einfo) + if settings.DEBUG is False: + detail = '{0!r} failed: {1!r}'.format(task_id, exc) + myLogger.error(detail) + send_mail_task.delay(subject='{}:{}_{}_task_error'.format(settings.SYS_NAME, settings.SYS_VERSION, settings.PROJECT_NAME), message=detail) + return super().on_failure(exc, task_id, args, kwargs, einfo)