芹菜工人没有运行:无法注册任务

时间:2014-07-06 05:19:53

标签: python django rabbitmq celery django-celery

芹菜工人正在给我一个错误说未注册的任务。我使用celeryd作为守护进程。重启没有帮助。

这是我的task.py celeryApp> tasks.py

from __future__ import absolute_import
from celery import task

@task
def add(a,b):
    return a+b

celeryProj.py<<我在celery.py中更改了名称,因为它正在创建问题

from __future__ import absolute_import
import os
from celery import Celery
from django.conf import settings

# Indicate Celery to use the default Django settings module
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'my_proj.settings')

app = Celery('my_app')
app.config_from_object('django.conf:settings')
# This line will tell Celery to autodiscover all your tasks.py that are in your app     folders
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)

__初始化__。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 .celeryProj import app as celeryApp

settings.py

from __future__ import absolute_import
import os
import sys
import djcelery
from celery.schedules import crontab


djcelery.setup_loader()

INSTALLED_APPS = (
    ..
    ...
    'my_app',
    'djcelery',
    'celeryApp',
)

BROKER_URL = "amqp://user:password@localhost:5672/v_host"

## celery configrations 

CELERY_TASK_SERIALIZER = 'json'
CELERY_RESULT_SERIALIZER = 'json'
CELERY_ACCEPT_CONTENT=['json']
CELERY_TIMEZONE = 'Asia/Kolkata'
CELERY_ENABLE_UTC = True

CELERY_RESULT_BACKEND='djcelery.backends.database:DatabaseBackend'
CELERYBEAT_SCHEDULER = 'djcelery.schedulers.DatabaseScheduler'

## These config can be commented in production

CELERY_BIN = "/usr/local/bin/celery"
CELERYD_NODES = "worker1 worker2 worker3"
CELERYD_CHDIR="/home/user/proj/"
CELERYD_OPTS="--time-limit=300 --concurrency=8"
CELERYD_USER="celery"
CELERYD_GROUP="celery"
CELERY_CREATE_DIRS=1


CELERY_IMPORTS = ('celeryApp.tasks',)

我的目录结构是:

myProj > my_app ,\_\_init\_\_.py, setting.py, celeryProj.py
myProj > celeryApp > tasks.py

我收到此错误日志:

[2014-07-06 10:17:43,674: ERROR/MainProcess] Received unregistered task of type u'celeryApp.tasks.add'.
The message has been ignored and discarded.

Did you remember to import the module containing this task?
Or maybe you are using relative imports?
Please see http://bit.ly/gLye1c for more information.

The full contents of the message body was:
{u'utc': True, u'chord': None, u'args': [2, 2], u'retries': 0, u'expires': None, u'task': u'celeryApp.tasks.add', u'callbacks': None, u'errbacks': None, u'timelimit': [None, None], u'taskset': None, u'kwargs': {}, u'eta': None, u'id': u'620007e6-4c7d-49cc-9516-4f089c200df9'} (260b)
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/celery/worker/consumer.py", line 455, in on_task_received
    strategies[name](message, body,
KeyError: u'celeryApp.tasks.add'

0 个答案:

没有答案