[ Django 1.9 + Celery unregistered tasks ]

This configuration is correct. I was starting celery the wrong way :(, without specifying the project name. (celery worker -A hockey_manager -l info

I did upgrade to Django 1.9 from 1.6.5 and I can't make the celery configuration work again.

After almost two days of searching for a solution I didn't find anything working.

Celery doesn't detect my tasks. I tried with:

  • CELERY_IMPORTS
  • autodiscover_tasks
  • bind=True

Dependencies

amqp==2.0.3 
celery==3.1.23 
Django==1.9.8 
django-celery==3.1.17
kombu==3.0.35

PROJECT STRUCTURE

enter image description here

hockey_manager/__init__.py

from __future__ import absolute_import

# 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

hockey_manager/celery.py

from __future__ import absolute_import

import os

from celery import Celery

# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'hockey_manager.settings.common')

app = Celery('hockey_manager')

# Using a string here means the worker will not have to
# pickle the object when using Windows.
app.config_from_object('django.conf:settings')

# load task modules from all registered Django app configs.
app.autodiscover_tasks(['hockey'])

# Using a string here means the worker will not have to
# pickle the object when using Windows.
# app.config_from_object('django.conf:settings')
# app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)

# Celery backend configs
app.conf.update(
    CELERY_RESULT_BACKEND='djcelery.backends.database:DatabaseBackend',
)

if __name__ == '__main__':
    app.start()


@app.task(bind=True)
def debug_task(self):
    print('Request: {0!r}'.format(self.request))

hockey_manager/settings/common.py

INSTALLED_APPS = [
    ...
    'hockey',
    'djcelery',
    'kombu.transport.django',
    ...
]

##
# Celery
##
# BROKER_POOL_LIMIT = 3
BROKER_URL = os.environ.get('CLOUDAMQP_URL')
#BROKER_URL = 'django://'

# List of modules to import when celery starts.
CELERY_IMPORTS = ('hockey.tasks', )

#: Only add pickle to this list if your broker is secured
#: from unwanted access (see userguide/security.html)

CELERY_ACCEPT_CONTENT = ['json']
CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'

hockey/tasks.py

from __future__ import absolute_import
from hockey_manager.celery import app

@app.task(name='hockey.tasks.league_schedule_results')
def league_schedule_results(schedule, statistics):
    ...

Error from Celery

[2016-07-23 17:05:46,231: ERROR/MainProcess] Received unregistered task of type 'hockey.tasks.league_schedule_results'. The message has been ignored and discarded.

I also receive a deprecation warning from amqp starting from version 2.0:

AMQPDeprecationWarning: The .transport attribute on the connection was accessed before the connection was established. This is supported for now, but will be deprecated in amqp 2.2.0.

Since amqp 2.0 you have to explicitly call Connection.connect()
before using the connection.

  W_FORCE_CONNECT.format(attr=attr)))

Answer 1


use django-celery module.

here is link to example how to use django-celery with django 1.9.1+