2
我是新來的芹菜,並試圖在我的應用程序中使用它。以下是我的基本應用程序結構芹菜「收到未註冊的任務」
my_app
|-run.py
|-app
|-mod1
|-mod2
|-tasks
|-__init__.py
|-email
|-other_tasks_file
我想將所有後臺任務都限制在我的任務模塊中。在INIT的.py的任務,我有
from celery import Celery
celery = Celery('my_app', broker='redis://localhost:6379/0')
我的任務範圍內
/電子郵件I have
from app.tasks import celery
@celery.task
def send_email():
#do stuff
從終端
我開始使用
celery -A app.tasks worker --loglevel=DEBUG
但我的任務工人沒有出現在芹菜的任務列表中。另外,一旦我跑我的任務從解釋像這樣
>>from app.tasks import email
>>email_result = email.send_email.delay()
當我做到這一點我得到我的芹菜終端以下響應
Received unregistered task of type 'app.tasks.emails.send_email'.
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 url for more information.
The full contents of the message body was:
{'kwargs': {}, 'taskset': None, 'id': '51e8f766-e772-4d85-bad0-5a6774ea541a', 'eta': None, 'timelimit': (None, None), 'args': [], 'retries': 0, 'task': 'app.tasks.emails.send_email', 'utc': True, 'errbacks': None, 'chord': None, 'expires': None, 'callbacks': None} (283b)
Traceback (most recent call last):
File "/usr/local/lib/python3.4/site-packages/celery/app/utils.py", line 235, in find_app
sym = symbol_by_name(app, imp=imp)
File "/usr/local/lib/python3.4/site-packages/celery/bin/base.py", line 492, in symbol_by_name
return symbol_by_name(name, imp=imp)
File "/usr/local/lib/python3.4/site-packages/kombu/utils/__init__.py", line 101, in symbol_by_name
return getattr(module, cls_name) if cls_name else module
AttributeError: 'module' object has no attribute 'tasks'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/local/lib/python3.4/site-packages/celery/worker/consumer.py", line 456, in on_task_received
strategies[name](message, body,
KeyError: 'app.tasks.channels.send_email'
我使用python 3.4和芹菜3.1.23