* test: Test send_review_reminders_task * refactor: Move send_scheduled_mail_task to message app * chore: Remove unused import * test: Add Message/SendQueue factories * test: Test send_scheduled_mail_task * test: Reset mocks before reuse * test: Cover error conditions * test: Return non-empty change set * test: Test SMTPException handling * test: Test fetch_attendance_from_meetings() * test: Test RuntimeError handling * test: RFC index sync should populate authors
28 lines
911 B
Python
28 lines
911 B
Python
# Copyright The IETF Trust 2024 All Rights Reserved
|
|
#
|
|
# Celery task definitions
|
|
#
|
|
from celery import shared_task
|
|
from smtplib import SMTPException
|
|
|
|
from ietf.message.utils import send_scheduled_message_from_send_queue
|
|
from ietf.message.models import SendQueue
|
|
from ietf.utils import log
|
|
from ietf.utils.mail import log_smtp_exception, send_error_email
|
|
|
|
|
|
@shared_task
|
|
def send_scheduled_mail_task():
|
|
"""Send scheduled email
|
|
|
|
This is equivalent to `ietf/bin/send-scheduled-mail all`, which was the only form used in the cron job.
|
|
"""
|
|
needs_sending = SendQueue.objects.filter(sent_at=None).select_related("message")
|
|
for s in needs_sending:
|
|
try:
|
|
send_scheduled_message_from_send_queue(s)
|
|
log.log('Sent scheduled message %s "%s"' % (s.id, s.message.subject))
|
|
except SMTPException as e:
|
|
log_smtp_exception(e)
|
|
send_error_email(e)
|