Answer the question
In order to leave comments, you need to log in
Received unregistered task of type, why is the task not registered?
How to manually add a task or set up auto-detection of tasks from other applications?
celery.py
project structure
# 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'
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']
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']
CELERY_IMPORTS = ('stats.views')
@task()
def collect_stats():
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question