celery task 放置位置问题

[tasks]
  . task.x2e

[2021-03-10 18:48:31,641: INFO/MainProcess] Connected to redis://127.0.0.1:6379/1
[2021-03-10 18:48:31,665: INFO/MainProcess] mingle: searching for neighbors
[2021-03-10 18:48:32,677: INFO/MainProcess] mingle: all alone
[2021-03-10 18:48:32,694: WARNING/MainProcess] celery@L-D011FD4C-0144 ready.
[2021-03-10 18:48:40,739: ERROR/MainProcess] Received unregistered task of type 'celery_api.task.x2e'.
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 http://bit.ly/gLye1c for more information.

The full contents of the message body was:
{'timelimit': (None, None), 'utc': True, 'chord': None, 'args': [], 'retries': 0, 'expires': None, 'task': 'celery_api.task.x2e', 'callbacks': None, 'errbacks': None, 'taskset': None, 'kwargs': {}, 'eta': None, 'id': '4407eb08-7b1e-4efc-a4d2-60f84d527cff'} (215b)
Traceback (most recent call last):
  File "d:\python2.7\lib\site-packages\celery\worker\consumer.py", line 465, in on_task_received
    strategies[type_](message, body,
KeyError: 'celery_api.task.x2e'

运行celery  worker 时是OK 的, 当提交task 就会出现上面的错误, 

解决:

  1、 查看 task 是否是在项目顶级目录中, 如果不是, 请改到顶级目录

  2、 task 只能监控同级别的目录及子目录, 上级目录是无法监控的, 基于此特点 我们应该尽量把 task 放在顶级目录

 

posted @ 2021-03-10 19:02  萤huo虫  阅读(173)  评论(0编辑  收藏  举报