diff --git a/README.md b/README.md index ad1606c..d060caf 100644 --- a/README.md +++ b/README.md @@ -83,7 +83,7 @@ EMAIL_HOST_PASSWORD = 'heslo k vasemu smtp serveru' Odesílání e-mailů se děje na pozadí - systém ukládá e-maily do fronty k odeslání, viz `Administrace - čekající zprávy`. Pro odeslání zprávy je třeba spustit následující příkaz: ``` -python manage.py svjis_send_messages +python manage.py db_worker --batch ``` Při testování aplikace ho můžete spouštět ručně. Při produkčním nastavení je potřeba nastavit plánovač systému (například cron) aby ho spoštěl v určitých itervalech (například každých 5 minut). diff --git a/svjis/articles/management/commands/svjis_send_messages.py b/svjis/articles/management/commands/svjis_send_messages.py deleted file mode 100644 index baddf16..0000000 --- a/svjis/articles/management/commands/svjis_send_messages.py +++ /dev/null @@ -1,9 +0,0 @@ -from django.core.management.base import BaseCommand -from articles import utils - - -class Command(BaseCommand): - help = "Send messages and empty message queue" - - def handle(self, *args, **options): - utils.send_message_queue() diff --git a/svjis/articles/utils.py b/svjis/articles/utils.py index 96d7fec..2cc1322 100644 --- a/svjis/articles/utils.py +++ b/svjis/articles/utils.py @@ -3,7 +3,6 @@ import secrets import string import os.path -import time from . import ( views, views_contact, @@ -163,19 +162,16 @@ def send_mails(recipient_list: list, subject: str, html_body: str, immediately: logger.warning(f"It seems E-Mail address is not valid: {r} - skipping it") else: models.MessageQueue.objects.create(email=r, subject=subject, body=html_body, status=0) + send_message_queue.enqueue() @task() def send_message_queue(): - for i in range(100): - print(i) - time.sleep(1) - - # messages = models.MessageQueue.objects.filter(status=0) - # for m in messages: - # send_mails([m.email], m.subject, m.body, True) - # m.status = 1 - # m.save() + messages = models.MessageQueue.objects.filter(status=0) + for m in messages: + send_mails([m.email], m.subject, m.body, True) + m.status = 1 + m.save() def get_template(template_key): diff --git a/svjis/articles/views_redaction.py b/svjis/articles/views_redaction.py index e007e04..35ac435 100644 --- a/svjis/articles/views_redaction.py +++ b/svjis/articles/views_redaction.py @@ -285,8 +285,7 @@ def redaction_article_notifications_send_view(request): users = get_users_for_notification(article) recipients = [u for u in users if request.POST.get(f"u_{u.pk}", False) == 'on'] - # utils.send_article_notification(recipients, f"{request.scheme}://{request.get_host()}", article) - utils.send_message_queue.enqueue() + utils.send_article_notification(recipients, f"{request.scheme}://{request.get_host()}", article) i = len(recipients) ctx = utils.get_context()