Catch errors in Django-Q2 email reporter

This commit is contained in:
Adam Goldsmith 2024-01-05 14:37:02 -05:00
parent edd26e3f75
commit 6ca6f1390c

View File

@ -1,4 +1,5 @@
import sys
import traceback
from django.views.debug import ExceptionReporter
from django.core import mail
@ -9,12 +10,15 @@ class AdminEmailReporter:
pass
def report(self):
reporter = ExceptionReporter(None, *sys.exc_info())
message = f"Failed to run task\n{reporter.get_traceback_text()}"
html_message = reporter.get_traceback_html()
mail.mail_admins(
"Django Q task failed",
message,
# fail_silently=True,
html_message=html_message,
)
try:
reporter = ExceptionReporter(None, *sys.exc_info())
message = f"Failed to run task\n{reporter.get_traceback_text()}"
html_message = reporter.get_traceback_html()
mail.mail_admins(
"Django Q task failed",
message,
# fail_silently=True,
html_message=html_message,
)
except Exception:
print(traceback.format_exc())