Commit 10928d91 authored by Robert's avatar Robert

Send task mails via dummy backend to allow debugging, refs #624

parent e9142ea1
Pipeline #1518 passed with stage
in 2 minutes and 18 seconds
......@@ -8,6 +8,7 @@ from django.apps import apps
from django.conf import settings
from django.contrib.sites.models import Site
from django.core import mail
from django.core.mail import get_connection
from django.template import loader
from core.models import PermissionToken
......@@ -18,8 +19,9 @@ logger = logging.getLogger(__name__)
class Notification:
@classmethod
def send_all(cls, instance):
def send_all(cls, instance, **extra_kwargs):
for recipient, kwargs in cls.get_recipients(instance).items():
kwargs.update(extra_kwargs)
cls(instance).send(recipient, **kwargs)
def __init__(self, instance):
......@@ -186,5 +188,9 @@ class Notification:
for file_name in self.get_attachments():
message.attach_file(file_name)
# optional connection switch
if kwargs.get('use_async_email_backend'):
message.connection = get_connection(settings.ASYNC_EMAIL_BACKEND)
# we don't expect errors when sending mails because we just pass mails to django-mailer
message.send()
......@@ -3,6 +3,7 @@ from datetime import timedelta
from django.dispatch import receiver, Signal
from django.utils.timezone import now
from features.content.notifications import ContentCreated
from features.content.tasks import send_content_notifications
post_create = Signal(providing_args=['instance'])
......@@ -11,4 +12,7 @@ post_create = Signal(providing_args=['instance'])
@receiver(post_create)
def content_created(sender, instance, **kwargs):
if now() - instance.versions.last().time_created < timedelta(weeks=1):
# send mails synchronously via default EMAIL_BACKEND
ContentCreated.send_all(instance)
# send mails asynchronously (task queue) via ASYNC_EMAIL_BACKEND
send_content_notifications(instance)
......@@ -5,4 +5,4 @@ from features.content.notifications import ContentCreated
@db_task()
def send_content_notifications(instance):
ContentCreated.send_all(instance)
ContentCreated.send_all(instance, use_async_email_backend=True)
import django.db.models.signals
from django.dispatch import receiver
from features.contributions.notifications import ContributionCreated
from features.contributions.tasks import send_contribution_notifications
......@@ -9,4 +10,7 @@ post_create = django.dispatch.Signal(providing_args=['instance'])
@receiver(post_create)
def contribution_created(sender, instance, **kwargs):
# send mails synchronously via default EMAIL_BACKEND
ContributionCreated.send_all(instance)
# send mails asynchronously (task queue) via ASYNC_EMAIL_BACKEND
send_contribution_notifications(instance)
......@@ -5,4 +5,4 @@ from features.contributions.notifications import ContributionCreated
@db_task()
def send_contribution_notifications(instance):
ContributionCreated.send_all(instance)
ContributionCreated.send_all(instance, use_async_email_backend=True)
......@@ -191,6 +191,7 @@ GROUPRISE_POSTMASTER_EMAIL = 'postmaster@localhost'
EMAIL_BACKEND = 'mailer.backend.DbBackend'
MAILER_EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
ASYNC_EMAIL_BACKEND = 'django.core.mail.backends.dummy.EmailBackend'
# Sites
......@@ -325,6 +326,5 @@ HAYSTACK_CONNECTIONS = {
HAYSTACK_XAPIAN_LANGUAGE = 'german2'
HUEY = {
# TODO: set to true if grouprise-huey is not available
'always_eager': False,
'always_eager': True,
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment