I have found this question and tried all recommendations as well as the accepted answer. Still no luck.
Here is my mysite/taskapp/celery.py:
import os
from celery import Celery
from django.apps import AppConfig
from django.conf import settings
if not settings.configured:
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings.local') # pragma: no cover
app = Celery('mysite')
class CeleryConfig(AppConfig):
name = 'mysite.taskapp'
verbose_name = 'Celery Config'
def ready(self):
app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks()
@app.task(bind=True)
def debug_task(self):
print('Request: {0!r}'.format(self.request)) # pragma: no cover
Here is my mysite's __init__.py:
from mysite.taskapp.celery import app as celery_app
__all__ = ['celery_app']
Here is an example mysite/myapp/tasks.py:
from celery import shared_task
@shared_task
def mytask():
print('Do something')
When running the celery worker with celery -A mysite worker -l info here is the output:
celery@tim-office v4.1.0 (latentcall)
Darwin-16.7.0-x86_64-i386-64bit 2018-02-27 21:38:55
[config]
.> app: mysite:0x1058e0fd0
.> transport: amqp://guest:**@localhost:5672//
.> results: disabled://
.> concurrency: 4 (prefork)
.> task events: OFF (enable -E to monitor tasks in this worker)
[queues]
.> celery exchange=celery(direct) key=celery
[tasks]
. mysite.taskapp.celery.debug_task
Note that the mysite/myapp/tasks.py tasks are not found. I've been spinning my wheels for a full day trying all kinds of things from adding the app to CELERY_IMPORTS in the settings file:
CELERY_IMPORTS = ('myapp.tasks',)
To trying to force them into autodiscover_tasksline in the abovemysite/taskapp/celery.py`:
app.autodiscover_tasks(['myapp',])
Where am I going wrong here? Any help is greatly appreciated.
UPDATE: Possibly worth noting I am using the project structure of cookiecutter-django.