I have created a django-celery application as in the tutorial at:
http://docs.celeryproject.org/en/master/django/first-steps-with-django.html
Everything works fine when I run it without application parameter as in:
$ python manage.py celery worker -l info
but I can't start it at all with the application parameter, as in:
$ python manage.py celery worker -A myapp -l info
where myapp is the name given to the application when I created the project with:
$ python manage.py startapp myapp
The error that I am getting is:
ImportError: No module named celery
Does anyone know why this happens and how to solve it?
Yes you can. Celery is a generic asynchronous task queue. In place of "django_project" you would point to your module.
If we try to run Celery on Windows, we will run into a problem: Windows is not officially supported by Celery.
Celery is an open-source Python library which is used to run the tasks asynchronously. It is a task queue that holds the tasks and distributes them to the workers in a proper manner. It is primarily focused on real-time operation but also supports scheduling (run regular interval tasks).
Edit April 2014:
The Celery docs have been updated for 3.1; the below solution is now outdated, see:
http://docs.celeryproject.org/en/master/django/first-steps-with-django.html
By default, celery searches for a module named celery.py
to find its configuration. You can get celery to use a different name than celery.py
by specify it on the app argument - in this example, we'll look for celery config in settings.py
:
python manage.py celery worker --app=myapp.settings
When using django-celery
you can either use the above call to start celery, or do as I originally did and create a celery.py
in my application package myapp
:
from settings import celery
My Django settings.py
contains the normal celery config:
from celery import Celery
celery = Celery(broker="amqp://guest:[email protected]:5672//")
celery.conf.update(
CELERY_DEFAULT_QUEUE = "myapp",
CELERY_DEFAULT_EXCHANGE = "myapp",
CELERY_DEFAULT_EXCHANGE_TYPE = "direct",
CELERY_DEFAULT_ROUTING_KEY = "myapp",
)
Then run the celery worker like this:
python manage.py celery worker --app=myapp
Just for clarity's sake, here's my full application structure:
myproject/
manage.py
myapp/
__init__.py
settings.py
celery.py
Be sure you're trying to start the celery worker from a directory that has access to the celery module. In my case I was trying to start the worker from the app directory rather than the project.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With