简体   繁体   English

尝试运行任务时,芹菜出现KeyError

[英]Getting a KeyError with celery when trying to run a task

I'm trying to run a celery task but am receiving a KeyError I'm guessing it's because celery is trying to get my tasks.py file from chatbot.tasks.add. 我正在尝试运行一个celery任务,但是收到一个KeyError我猜是因为celery试图从chatbot.tasks.add中获取我的tasks.py文件。 However me being stupid I put the add() module in my local bot/tasks directory. 但是我很愚蠢,所以将add()模块放在本地bot / tasks目录中。 Which is what is causing the error. 这是导致错误的原因。 I thought I could fix this problem by just instead doing from chatbot.tasks import add when I'm in my Python shell but I keep getting a "no module named..." error. 我以为我可以通过改用from chatbot.tasks import add来解决此问题,当我进入Python外壳程序时,却不断收到“没有名为...的模块”错误。

So how do I successfully pass the correct key (chatbot.tasks.add) to celery in the shell now? 那么,如何立即将正确的密钥(chatbot.tasks.add)传递给Shell中的celery?

EDIT: Traceback Error: 编辑:回溯错误:

[2018-02-13 04:32:47,609: INFO/MainProcess] Connected to amqp://guest:**@127.0.0.1:5672//
[2018-02-13 04:32:47,628: INFO/MainProcess] mingle: searching for neighbors
[2018-02-13 04:32:48,641: INFO/MainProcess] mingle: all alone
[2018-02-13 04:32:48,674: WARNING/MainProcess] celery@Charles-PC ready.
[2018-02-13 04:33:52,023: ERROR/MainProcess] Received unregistered task of type 'bot.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 --- for more information.

The full contents of the message body was:
{'timelimit': (None, None), 'utc': True, 'chord': None, 'args': (2, 3), 'retries': 0, 'expires': None, 'task': 'bot.tasks.add
075-4bb0-89e5-b33a545c11f4'} (213b)
Traceback (most recent call last):
  File "c:\users\elitebook\.virtualenvs\chatbot\lib\site-packages\celery\worker\consumer.py", line 455, in on_task_received
    strategies[name](message, body,
KeyError: 'bot.tasks.add'

I don't know your application layout but in my celery project (which is almost 3 years old) I have two files: celeryconfig.py and celery.py . 我不知道您的应用程序布局,但是在我的celery项目(将近3年)中,我有两个文件: celeryconfig.pycelery.py Within celery.py I am importing all my tasks so I can then refer to them from other packages that import my project or when I want to run celery beat task. celery.py中,我将导入所有任务,以便随后可以从导入我的项目的其他软件包中或在要运行celery beat任务时引用它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM