Skip to content
Snippets Groups Projects
Commit eaf3ad1f authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Merge branch '312-send-emails-for-celery-tasks-with-status-failure' into 'master'

Resolve "Send emails for celery tasks with status "FAILURE""

Closes #312

See merge request !877
parents 70b78f85 1ccd7a7d
No related branches found
No related tags found
1 merge request!877Resolve "Send emails for celery tasks with status "FAILURE""
Pipeline #49381 canceled
......@@ -13,6 +13,7 @@ Added
~~~~~
* Add preference for configuring the default phone number country code.
* Admins recieve an mail for celery tasks with status "FAILURE"
Added
~~~~~
......
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),
},
)
{% load i18n %}
{% block subject %}
{% blocktrans with task_name=task_name%} Celery task {{ task_name }} failed!{% endblocktrans %}
{% endblock %}
{% block plain %}
{% trans "Hello," %}
{% blocktrans with task_name=task_name %}
the celery task {{ task_name }} failed with following information:
{% endblocktrans %}
{% blocktrans with task_name=task_name task=task task_id=task_id exception=exception args=args kwargs=kwargs traceback=traceback %}
* Task name: {{task_name}}
* Task: {{task}}
* Id of the task: {{task_id}}
* Exception instance raised: {{ exception }}
* Positional arguments the task was called with: {{ args }}
* Keyword arguments the task was called with: {{ kwargs }}
* Stack trace object: {{ traceback }}
{% endblocktrans %}
{% endblock %}
{% block html %}
<p>{% trans "Hello," %}</p>
<p>
{% blocktrans with task_name=task_name %}
the celery task {{ task_name }} failed with following information:
{% endblocktrans %}
</p>
<ul>
{% blocktrans with task_name=task_name task=task task_id=task_id exception=exception args=args kwargs=kwargs traceback=traceback %}
<li>Task name: {{task_name}}</li>
<li>Task: {{task}}</li>
<li>Id of the task: {{task_id}}</li>
<li>Exception instance raised: {{ exception }}</li>
<li>Positional arguments the task was called with: {{ args }}</li>
<li>Keyword arguments the task was called with: {{ kwargs }}</li>
<li>Stack trace object: {{ traceback }}</li>
</ul>
{% endblocktrans %}
{% endblock %}
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