Skip to content
Snippets Groups Projects
Commit 8acdd802 authored by Benedict Suska's avatar Benedict Suska
Browse files

Send mail to admins if celery tasks fail

parent 7909b6d3
No related branches found
No related tags found
1 merge request!877Resolve "Send emails for celery tasks with status "FAILURE""
import os
from django.conf import settings
from celery import Celery
from celery.signals import task_failure
from templated_email import send_templated_mail
from .util.core_helpers import get_site_preferences
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "aleksis.core.settings")
app = Celery("aleksis") # noqa
app.config_from_object("django.conf:settings", namespace="CELERY")
app.autodiscover_tasks()
@task_failure.connect
def task_failure_notifier(
sender=None, task_id=None, exception=None, args=None, traceback=None, **kwargs
):
recipient_list = [e[1] for e in settings.ADMINS]
send_templated_mail(
template_name="celery_failure",
from_email=get_site_preferences()["mail__address"],
recipient_list=recipient_list,
context={
"task_name": sender.name,
"task": str(sender),
"task_id": str(task_id),
"exception": str(exception),
"args": str(args),
"kwargs": str(kwargs),
"traceback": str(traceback),
},
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment