Couldn't apply scheduled task task-name: send_mail_about_updates() missing 2 required positional arguments: 'recipient_email' and 'course_name'

13 Views Asked by At
celery.beat.SchedulingError: Couldn't apply scheduled task task-name: send_mail_about_updates() missing 2 required positional arguments: 'recipient_email' and 'course_name

tasks.py

from celery import shared_task
from django.core.mail import send_mail
from django.conf import settings


@shared_task
def send_mail_about_updates(recipient_email, course_name):
    send_mail(
        subject='course update notification',
        message=f"Курс {course_name} обновлен. Ознакомьтесь с новыми материалами!",
        from_email=settings.EMAIL_HOST_USER,
        recipient_list=[recipient_email],
        fail_silently=False
    )

views.py

class CourseUpdateApiView(generics.UpdateAPIView):
    queryset = Course.objects.all()
    serializer_class = CourseSerializer
    permission_classes = [IsAuthenticated]

    def update(self, request, *args, **kwargs):
        instance = self.get_object()
        print(instance.name)

        subscribed_users = instance.get_subscribed_users()
        
        for user in subscribed_users:
            if user.email:
                try:
                    send_mail_about_updates.delay(recipient_email=user.email,
course_name=instance.name)
                except Exception as emails:
                    logger.error(f"Не удалось отправить электронное письмо на адрес     {user.email}: {emails}")

        return super().update(request, *args, **kwargs)

I did this, it doesn't work

from celery import shared_task
from django.core.mail import send_mail

@shared_task
def send_mail_about_updates(recipient_email, course_name):
    send_mail(
        'Subject here',
        'Here is the message.',
        '[email protected]',
        [recipient_email],
        fail_silently=False,
    )`
0

There are 0 best solutions below