I’m having problems with celery, which I use to send emails. Particularly the code was working and from one moment to another it stopped working and I can’t find why.
Another thing I notice is that the celery documentation is not very good, so here is my first question. Is it advisable to continue with celery? Or is it better to start from scratch with another?
This is what I get when from celery:
[2022-10-08 00:02:31,138: ERROR/MainProcess] Received unregistered task of type ‘callserviceapp.tasks.send_user_mail’.
The message has been ignored and discarded.
Did you remember to import the module containing this task?
Or maybe you are using relative imports?
Please see http://bit.ly/gLye1c for more information.
The url http://bit.ly/gLye1c to get more data is not working.
And this is the code:
# This will make sure the app is always imported when # Django starts so that shared_task will use this app. from celery import app as celery_app __all__ = ('celery_app',)
from __future__ import absolute_import, unicode_literals import os from celery import Celery from django.conf import settings os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'callservices.settings') app = Celery('callservices') app.config_from_object('django.conf:settings', namespace='CELERY') app.autodiscover_tasks( lambda: settings.INSTALLED_APPS + settings.INSTALLED_APPS_WITH_APPCONFIGS ) @app.task() def debug_task(): print("hi all")
from celery import shared_task from django.core.mail import EmailMultiAlternatives, send_mail @shared_task(bind=True) def send_user_mail(randomNumber, email): subject = 'xxxxxxxx' body="xxxxxx: "+str(randomNumber) send_mail(subject, body ,'email@example.com', [email],fail_silently = False) ) return 1
I also add this lines in settings.py
BROKER_URL = 'amqp://' CELERY_RESULT_BACKEND = 'amqp://' CELERY_TASK_SERIALIZER = 'json' CELERY_RESULT_SERIALIZER = 'json' CELERY_TIMEZONE = 'America/Los_Angeles' CELERY_ENABLE_UTC = True CELERY_IMPORTS = ("tasks",)