Skip to content

Commit

Permalink
Django tasks e-mail test
Browse files Browse the repository at this point in the history
  • Loading branch information
berk76 committed Dec 10, 2024
1 parent b2fbbae commit 0bddfb8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 22 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
9 changes: 0 additions & 9 deletions svjis/articles/management/commands/svjis_send_messages.py

This file was deleted.

16 changes: 6 additions & 10 deletions svjis/articles/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import secrets
import string
import os.path
import time
from . import (
views,
views_contact,
Expand Down Expand Up @@ -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):
Expand Down
3 changes: 1 addition & 2 deletions svjis/articles/views_redaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 0bddfb8

Please sign in to comment.