Я использую Django==2.0.5
и celery==4.0.2
.Мой proj/proj/celery.py
выглядит так:
from __future__ import absolute_import, unicode_literals
import os
from celery import Celery
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'proj.settings')
app = Celery('proj', include=[])
# Using a string here means the worker doesn't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
# should have a `CELERY_` prefix.
app.config_from_object('django.conf:settings', namespace='CELERY')
# Load task modules from all registered Django app configs.
# app.autodiscover_tasks()
@app.task(bind=True)
def debug_task(self):
print('Request: {0!r}'.format(self.request))
Я ожидал, что ни одна из задач, отмеченных shared_task
в tasks.py
приложений, не будет обнаружена, но, к моему удивлению, большинство задач может бытьвидно под [tasks]
при запуске celery worker
с celery worker -A proj -l INFO
.
Моя структура каталогов выглядит примерно так:
app
│ ├── __init__.py
│ ├── admin.py
│ ├── apps.py
│ ├── constants.py
│ ├── scripts
│ │ ├── __init__.py
│ ├── factories.py
│ ├── migrations
│ │ ├── 0001_initial.py
│ │ ├── __init__.py
│ ├── models.py
│ ├── tasks.py
│ └── tests
│ ├── __init__.py
CELERY_IMPORTS
не установлена в settings.py
, и у меня естьдаже с CELERY_IMPORTS=()
и CELERY_IMPORTS=['path/to/one/of/the/modules']
, даже тогда все задачи обнаруживаются.
Любые предложения приветствуются.