python - 如何修复接收未注册任务错误 - Celery

标签 python linux rabbitmq celery

我正在尝试使用 Celery (4.2.0) 和 RabbitMQ (3.7.14) 在使用 Ubuntu 16.04 的 Azure VM 上运行 Python 3.7.2 建立一个周期性任务。我能够启动节拍和工作人员,并看到消息从节拍开始发送给工作人员,但此时我遇到了这样的错误

[2019-03-29 21:35:00,081: ERROR/MainProcess] Received 
unregistered task of type 'facebook-call.facebook_api'.
The message has been ignored and discarded.

Did you remember to import the module containing this task?
Or maybe you're using relative imports?

我的代码如下:

from celery import Celery
from celery.schedules import crontab

app = Celery('facebook-call', broker='amqp://localhost//')

@app.task
def facebook_api():
    {function here}

app.conf.beat.schedule = {
    'task': 'facebook-call.facebook_api',
    'schedule': crontab(hour=0, minute =0, day='0-6'),
}

我使用包含所有代码的 python 文件的名称启动节拍和工作进程

celery -A FacebookAPICall beat --loglevel=info
celery -A FacebookAPICall worker --loglevel=info

beat 进程再次启动,我可以看到消息已成功传递给 worker,但无法弄清楚如何“注册”任务以便由 worker 处理它。

最佳答案

我能够通过将应用程序从 facebook-call 重命名为与文件名 FacebookAPICall 一致来解决问题

之前: app = Celery('facebook-call', broker='amqp://localhost//'

之后: app = Celery('FacebookAPICall', broker='amqp://localhost//'

通过阅读 Celery 文档,我不完全理解为什么应用程序的名称也必须是 .py 文件的名称,但这似乎可以解决问题。

关于python - 如何修复接收未注册任务错误 - Celery,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55427015/

相关文章:

python - Stty 疯狂地使用 Python 子进程

java - 使用 spring-rabbit 从消息中提取 header ,无需在注释中声明队列

python - 我试图写入 txt.file 的函数有什么问题?

python - 在python中将类似字符串的对象转换为字符串

python - 我在专栏中失去了我的值(value)观

linux - 通过运行脚本检测文件读/写

Python:在一组数字中排序

linux - 删除特定单词之间带有 VIM 的 .txt 的内容

RabbitMQ 上的 Spring 集成和 AMQP 抛出异常 Method handleToken(byte[]) 找不到

java - RabbitMQ 对 EC2 性能的挑战