gpt4 book ai didi

python - celery "received unregistered task"

转载 作者:太空宇宙 更新时间:2023-11-03 12:15:59 26 4
gpt4 key购买 nike

我是 celery 的新手,正试图在我的应用程序中使用它。以下是我的基本应用结构

 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

但是我的任务没有出现在celery的任务列表中。另外,一旦我像这样从解释器运行我的任务

>>from app.tasks import email
>>email_result = email.send_email.delay()

当我这样做时,我在我的 celery 终端中得到以下响应

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 和 celery 3.1.23

最佳答案

如果有人需要它,我终于让它工作了。我需要做的是为包含任务的实际文件运行 celery worker,以便 celery 注册任务 -

celery -A app.tasks.emails worker --loglevel=DEBUG  

因为只是运行

celery -A app.tasks worker --loglevel=DEBUG

(这是我的大胆猜测)实际上不会导入我的 send_email() 任务。如果有人可以给我一个解释,请这样做。

关于python - celery "received unregistered task",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37225803/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com