From dbe165c0689d90d7c56305d726054fc27d104ce7 Mon Sep 17 00:00:00 2001 From: glic3 Date: Mon, 4 May 2015 22:26:01 +0200 Subject: [PATCH] Added mailer --- TODO.md | 5 ----- orchestra/contrib/mailer/backends.py | 1 + orchestra/contrib/mailer/engine.py | 3 +-- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/TODO.md b/TODO.md index a449e93d..d7bd41f0 100644 --- a/TODO.md +++ b/TODO.md @@ -311,11 +311,8 @@ Replace celery by a custom solution? *priority: custom Thread backend *bulk: wrapper arround django-mailer to avoid loading django system - pip3 install https://github.com/APSL/django-mailer-2/archive/master.zip - - # TASKS_ENABLE_UWSGI_CRON_BEAT (default) for production + system check --deploy if 'wsgi' in sys.argv and settings.TASKS_ENABLE_UWSGI_CRON_BEAT: import uwsgi @@ -326,8 +323,6 @@ pip3 install https://github.com/APSL/django-mailer-2/archive/master.zip # TASK_BEAT_BACKEND = ('cron', 'celerybeat', 'uwsgi') # SHip orchestra production-ready (no DEBUG etc) - - # import module and sed # if setting.value == default. remove # reload generic admin view ?redirect=http... diff --git a/orchestra/contrib/mailer/backends.py b/orchestra/contrib/mailer/backends.py index d6cd0f59..cfa8748a 100644 --- a/orchestra/contrib/mailer/backends.py +++ b/orchestra/contrib/mailer/backends.py @@ -12,6 +12,7 @@ class EmailBackend(BaseEmailBackend): if not email_messages: return num_sent = 0 + # TODO if multiple messages queue, else async? for message in email_messages: priority = message.extra_headers.get('X-Mail-Priority', Message.NORMAL) if priority == Message.CRITICAL: diff --git a/orchestra/contrib/mailer/engine.py b/orchestra/contrib/mailer/engine.py index 9ed40abb..62b9e40c 100644 --- a/orchestra/contrib/mailer/engine.py +++ b/orchestra/contrib/mailer/engine.py @@ -12,7 +12,7 @@ def send_message(message, num, connection, bulk): connection.close() connection = None if connection is None: - # Reset connection + # Reset connection with django connection = get_connection(backend='django.core.mail.backends.smtp.EmailBackend') connection.open() error = None @@ -44,7 +44,6 @@ def send_pending(bulk=100): for retries, seconds in enumerate(settings.MAILER_DEFERE_SECONDS): delta = timedelta(seconds=seconds) qs = qs | Q(retries=retries, last_retry__lte=now-delta) - for message in Message.objects.filter(state=Message.DEFERRED).filter(qs).order_by('priority'): send_message(message, num, connection, bulk) if connection is not None: