celery 相关问题

一、 celery SQS 的 pycurl 问题

celery 利用 AWS SQS 安装 pycurl 时会出现 “ImportError: pycurl” 相关的错误,解决方法如下:

  1.  先把原先安装的 pycurl 删除
  2.  重新安装 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

https://stackoverflow.com/questions/9769496/celery-received-unregistered-task-of-type-run-example#52549375

 

附: 链接跳转到页面的指定部分:需要页面的该部分有 "name" 属性

链接:

https://blog.csdn.net/alokka/article/details/74640873

https://blog.csdn.net/GreyBearChao/article/details/73344241

 

posted @   neozheng  阅读(890)  评论(3编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 零经验选手,Compose 一天开发一款小游戏!
· 因为Apifox不支持离线,我果断选择了Apipost!
· 通过 API 将Deepseek响应流式内容输出到前端
历史上的今天:
2019-09-30 Flask:上下文管理
点击右上角即可分享
微信分享提示