[Django]-Why can't Celery daemon see tasks?

2👍

Looks like it is happening due to relative import error.

>>> from project.myapp.tasks import mytask
>>> mytask.name
'project.myapp.tasks.mytask'

>>> from myapp.tasks import mytask
>>> mytask.name
'myapp.tasks.mytask'

If you’re using relative imports you should set the name explicitly.

@task(name='proj.tasks.add')
def add(x, y):
   return x + y

Checkout: http://celery.readthedocs.org/en/latest/userguide/tasks.html#automatic-naming-and-relative-imports

2👍

I’m using celery 4.0.2 and django, and I created a celery user and group for use with celeryd and had this same problem. The command-line version worked fine, but celeryd was not registering the tasks. It was NOT a relative naming problem.

The solution was to add the celery user to the group that can access the django project. In my case, this group is www-data with read, execute, and no write.

Leave a comment