Catch errors in Django-Q2 email reporter

This commit is contained in:
Adam Goldsmith 2024-01-05 14:37:02 -05:00
parent 188824d53b
commit da0767a0e9

View File

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