Как вручную добавить таск или настроить автонахождение тасков из других приложений?
Структура проекта
celery.py
# coding: utf8
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', 'backend.settings')
app = Celery('backend')
# 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()
# Redis
app.conf.broker_url = 'redis://redis:6379/0'
@app.task(bind=True)
def debug_task(self):
print('Request: {0!r}'.format(self.request))
# Celery beat
app.conf.beat_schedule = {
'scheduled': {
'task': 'api.controllers.message.scheduled_message',
'schedule': 60.0
},
'collection_of_statics': {
'task': 'stats.views.collect_stats',
'schedule': 60.0
}
}
app.conf.timezone = 'UTC'
backend/__init__.py
from __future__ import absolute_import, unicode_literals
# This will make sure the app is always imported when
# Django starts so that shared_task will use this app.
from .celery import app as celery_app
__all__ = ['celery_app']
settings.py
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'api',
'stats',
'corsheaders',
]
Зарегистрированные таски
flower_1 | [I 180221 09:28:27 command:147] Registered tasks:
flower_1 | ['CallbackNotifier',
flower_1 | 'FB posting',
flower_1 | 'FB token status',
flower_1 | 'MD posting',
flower_1 | 'MD token status',
flower_1 | 'OK posting',
flower_1 | 'OK token status',
flower_1 | 'TW posting',
flower_1 | 'TW token status',
flower_1 | 'VK posting',
flower_1 | 'VK token status',
flower_1 | 'api.controllers.message.scheduled_message',
flower_1 | 'backend.celery.debug_task',
flower_1 | 'celery.accumulate',
flower_1 | 'celery.backend_cleanup',
flower_1 | 'celery.chain',
flower_1 | 'celery.chord',
flower_1 | 'celery.chord_unlock',
flower_1 | 'celery.chunks',
flower_1 | 'celery.group',
flower_1 | 'celery.map',
flower_1 | 'celery.starmap']
Таски, которые находятся в приложении api находит без проблем, с приложения stats не подтягивает
Пробовал добавить в settings.py
CELERY_IMPORTS = ('stats.views')
Таск, который нужно добавить с stats.views
@task()
def collect_stats():
Какое решение посоветуете?