简体   繁体   中英

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. However me being stupid I put the add() module in my local bot/tasks directory. 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.

So how do I successfully pass the correct key (chatbot.tasks.add) to celery in the shell now?

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 . 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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