celery 相关问题
一、 celery SQS 的 pycurl 问题
celery 利用 AWS SQS 安装 pycurl 时会出现 “ImportError: pycurl” 相关的错误,解决方法如下:
- 先把原先安装的 pycurl 删除
- 重新安装 pycurl,安装步骤如下:
安装命令:
# 1. Exporting two constants (as stated here pyca/cryptography#3489): export CPPFLAGS=-I/usr/local/opt/openssl/include export LDFLAGS=-L/usr/local/opt/openssl/lib # Installing with pip pip install pycurl --global-option="--with-openssl"
参考链接:
https://github.com/transloadit/python-sdk/issues/4#issuecomment-347009356
二、 celery 任务没有被注册的问题
问题大致如下:
[2020-09-30 11:04:45,917: ERROR/MainProcess] Received unregistered task of type 'tasks.xxx.xxxxxxxxx'. The message has been ignored and discarded. Did you remember to import the module containing this task? Or maybe you're using relative imports? Please see http://docs.celeryq.org/en/latest/internals/protocol.html for more information. The full contents of the message body was: b'xxxxxxxx' (367b) Traceback (most recent call last): File "/xxxxxx/venv/lib/python3.6/site-packages/celery/worker/consumer/consumer.py", line 555, in on_task_received strategy = strategies[type_] KeyError: 'tasks.xxx.xxxxxxxxx'
解决方法:
在创建 celery 的时候加上 include=['tasks.asyn_tasks'] ,列表中的内容表示任务的模块的路径
from celery import Celery def make_celery(app): celery = Celery( app.import_name, backend=app.config['CELERY_RESULT_BACKEND'], broker=app.config['CELERY_BROKER_URL'], include=['tasks.asyn_tasks'] # 加上 include 任务路径 ) celery.conf.update(app.config) class ContextTask(celery.Task): def __call__(self, *args, **kwargs): with app.app_context(): return self.run(*args, **kwargs) celery.Task = ContextTask return celery
参考链接:
https://stackoverflow.com/questions/46523635/received-unregistered-task-of-type-in-flask-celery
附: 链接跳转到页面的指定部分:需要页面的该部分有 "name" 属性
链接:
https://blog.csdn.net/alokka/article/details/74640873
https://blog.csdn.net/GreyBearChao/article/details/73344241
Code your future.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 因为Apifox不支持离线,我果断选择了Apipost!
· 通过 API 将Deepseek响应流式内容输出到前端
2019-09-30 Flask:上下文管理