10đź‘Ť
I believe your tasks.py file needs to be in a django app (that’s registered in settings.py) in order to be imported. Alternatively, you might try importing the tasks from an __init__.py
file in your main project or one of the apps.
Also try starting celeryd from manage.py:
$ python manage.py celeryd -E -B -lDEBUG
(-E
and -B
may or may not be necessary, but that’s what I use).
11đź‘Ť
This is what I did which finally worked
in Settings.py I added
CELERY_IMPORTS = ("myapp.jobs", )
under myapp folder I created a file called jobs.py
from celery.decorators import task
@task(name="jobs.add")
def add(x, y):
return x * y
Then ran from commandline: python manage.py celeryd -l info
in another shell i ran python manage.py shell, then
>>> from myapp.jobs import add
>>> result = add.delay(4, 4)
>>> result.result
and the i get:
16
The important point is that you have to rerun both command shells when you add a new function. You have to register the name both on the client and and on the server.
🙂
- Django admin, extending admin with custom views
- How to start a long-running process from a Django view?
- How do I use .env in Django?
- How to make sure Django models match the database schema
- Create a canonical "parent" product in Django Oscar programmatically
5đź‘Ť
See Automatic Naming and Relative Imports, in the docs:
http://celeryq.org/docs/userguide/tasks.html#automatic-naming-and-relative-imports
The tasks name is “tasks.Submitter” (as listed in the celeryd output),
but you import the task as “fable.jobs.tasks.Submitter”
I guess the best solution here is if the worker also sees it as “fable.jobs.tasks.Submitter”,
it makes more sense from an app perspective.
CELERY_IMPORTS = ("fable.jobs.tasks", )
- Django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty
- Gunicorn will not bind to my application
- Django sekizai {% addtoblock %} tag is not working properly
- Casting from base Model instance to derived proxy Model in Django?
- Convert data on AlterField django migration