python - 如何修复接收未注册任务错误 - 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
同样,节拍过程开始,我可以看到消息已成功传递给工作人员,但无法弄清楚如何“注册”任务以便由工作人员处理。
解决方案
我能够通过将应用程序重命名facebook-call
为与文件名一致来解决问题FacebookAPICall
前:
app = Celery('facebook-call', broker='amqp://localhost//'
后:
app = Celery('FacebookAPICall', broker='amqp://localhost//'
通过阅读 Celery 文档,我不完全理解为什么应用程序的名称也必须是.py
文件的名称,但这似乎可以解决问题。
推荐阅读
- c# - 如何比较两个装箱变量(不知道它们是否可以转换为另一个类型,或者它们是值类型还是引用类型)?
- python - 遍历所有 odoo 产品并更新其记录的最佳方法是什么?
- python - Pandas value_count 手动设置间隔而不是相等的间隔
- angular - 帖子应该重定向到不同的页面
- java - 从 REST API 过滤 JSON 对象的疑问
- scala - 在尝试遍历消费者记录时,每个循环中的 Scala 中的错误
- kotlin - JSON 解析错误:语法错误,期望 {,实际错误,pos 0,fastjson-version 1.2.57 使用 RoyalPay SDK 时
- amazon-s3 - S3 浏览器客户端不会显示存储桶根文件夹中的对象
- android - 在 RxJava 中传递参数时顺序运行 Observables
- javascript - 使用 Nuxt 和 Vuetify 的头像选择器