-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d2eb123
commit 65acd80
Showing
2 changed files
with
48 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
from celery import group, shared_task | ||
|
||
from api.v1.utils import send_mail | ||
from urban_utopia_2024.app_data import CHUNK_EMAIL | ||
from user.models import User | ||
|
||
|
||
@shared_task | ||
def send_mass_mail(subject: str, message: str, user_emails: list[str]) -> None: | ||
"""Отправляет письма указанным адресатам в user_emails.""" | ||
for email in user_emails: | ||
send_mail(subject=subject, message=message, to=(email,)) | ||
return | ||
|
||
|
||
@shared_task | ||
def send_mass_mail_async(subject: str, message: str) -> None: | ||
"""Задача по рассылке писем пользователям.""" | ||
user_emails: list[str] = User.objects.filter( | ||
is_staff=False, | ||
is_municipal=False, | ||
).values_list( | ||
'email', | ||
flat=True, | ||
) | ||
user_groups: list[list[str]] = [ | ||
user_emails[i:(i+CHUNK_EMAIL)] for | ||
i in range(0, len(user_emails), CHUNK_EMAIL) | ||
] | ||
celery_group: group = group( | ||
send_mass_mail.s( | ||
subject=subject, | ||
message=message, | ||
user_emails=user_group | ||
) for user_group in user_groups | ||
) | ||
celery_group.apply_async() | ||
return |