我对芹菜还不太熟悉,想在我的应用程序中使用它。下面是我的基本应用程序结构
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')
在我的任务/电子邮件中
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'
我正在使用Python3.4和芹菜3.1.23
如果有人需要的话,我终于让它工作了。 我需要做的是为包含任务的实际文件运行一个芹菜工人,以便芹菜注册任务-
因为只是跑步
(这是我的猜测)实际上不会导入我的send_email()任务。如果有人能给我一个解释,请做。
相关问题 更多 >
编程相关推荐