cmsmanage/cmsmanage/django_q2_admin_email_reporter.py

25 lines
674 B
Python

import sys
import traceback
from django.core import mail
from django.views.debug import ExceptionReporter
class AdminEmailReporter:
def __init__(self, **kwargs):
pass
def report(self):
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())