Celery 4.3.0的新功能:What’s new in Celery 4.3 (rhubarb)
作者: Omer Katz (omer.drow at gmail.com)
Celery
是一个用于处理大批量的消息的简单,灵活并且可靠的分布式程序框架,并且提供了以 Python
编写的用于维护一个分布式系统必要的工具。它是一个专注与实时处理的任务队列,并且也支持定时任务。
虽然此版本向后兼容之前发布的版本,但阅读下方的章节也是很重要的。
当前版本官方支持 CPython 2.7,3.4,3.5,3.6 & 3.7 ,并且也支持 PyPY2 和 PyPy3。
4.3.0 版本继续改进我们的工作,以为你提供
Python
语言下最好的任务执行平台。此版本重点关注于新的功能点,例如新的结果后端以及经过改进的安全的序列化器,以及主要针对于 Celery Beat,Canvas的 bug 修复,一些对职程挂起的重要修复和一些针对内存严重泄露的修复。
Celery 4.3 是第一个支持 Python 3.7 的版本。
我们希望 4.3 版本是在我们开始编写 Celery 5 版本,下一代的任务执行平台,时最后一个支持 Python 2.7 的版本。
但是如果 Celery 5 由于一些原因而延迟发布,我们可能会发布另一个 4.x 的版本来支持 Python 2.7。
如果要发布另一个 4.x 的版本,它将会放弃对 Python 3.4 的支持,因为 Python 3.4 的寿命截止到 2019 年 5 月。
我们也致力于解决贡献冲突的问题。
我也添加了一些问题的模板,我们将继续对其进行改进,以便于您打开的问题可以包含有利于我们解决问题的更多相关的信息。
---- Omer Katz
Alexander Ioannidis <[email protected]> Amir Hossein Saeid Mehr <[email protected]> Andrea Rabbaglietti <[email protected]> Andrey Skabelin <[email protected]> Anthony Ruhier <[email protected]> Antonin Delpeuch <[email protected]> Artem Vasilyev <[email protected]> Asif Saifuddin Auvi <[email protected]> Asif Saif Uddin (Auvi) <[email protected]> Asif Saif Uddin <[email protected]> aviadatsnyk <[email protected]> Axel Haustant <[email protected]> Benjamin Pereto <[email protected]> Bojan Jovanovic <[email protected]> Brett Jackson <[email protected]> Brett Randall <[email protected]> Brian Schrader <[email protected]> Bruno Alla <[email protected]> Buddy <[email protected]> Charles Chan <[email protected]> Christopher Dignam <[email protected]> Ciaran Courtney <[email protected]> Clemens Wolff <[email protected]> Colin Watson <[email protected]> Daniel Hahler <[email protected]> Dash Winterson <[email protected]> Derek Harland <[email protected]> Dilip Vamsi Moturi <[email protected]> Dmytro Litvinov <[email protected]> Douglas Rohde <[email protected]> Ed Morley <[email protected]> Fabian Becker <[email protected]> Federico Bond <[email protected]> Fengyuan Chen <[email protected]> Florian CHARDIN <[email protected]> George Psarakis <[email protected]> Guilherme Caminha <[email protected]> ideascf <[email protected]> Itay <[email protected]> Jamie Alessio <[email protected]> Jason Held <[email protected]> Jeremy Cohen <[email protected]> John Arnold <[email protected]> Jon Banafato <[email protected]> Jon Dufresne <[email protected]> Joshua Engelman <[email protected]> Joshua Schmid <[email protected]> Josue Balandrano Coronel <[email protected]> K Davis <[email protected]> kidoz <[email protected]> Kiyohiro Yamaguchi <[email protected]> Korijn van Golen <[email protected]> Lars Kruse <[email protected]> Lars Rinn <[email protected]> Lewis M. Kabui <[email protected]> madprogrammer <[email protected]> Manuel Vázquez Acosta <[email protected]> Marcus McHale <[email protected]> Mariatta <[email protected]> Mario Kostelac <[email protected]> Matt Wiens <[email protected]> Maximilien Cuony <[email protected]> Maximilien de Bayser <[email protected]> Meysam <[email protected]> Milind Shakya <[email protected]> na387 <[email protected]> Nicholas Pilon <[email protected]> Nick Parsons <[email protected]> Nik Molnar <[email protected]> Noah Hall <[email protected]> Noam <[email protected]> Omer Katz <[email protected]> Paweł Adamczak <[email protected]> peng weikang <[email protected]> Prathamesh Salunkhe <[email protected]> Przemysław Suliga <[email protected]> Raf Geens <[email protected]> (◕ᴥ◕) <[email protected]> Robert Kopaczewski <[email protected]> Samuel Huang <[email protected]> Sebastian Wojciechowski <[email protected]> Seunghun Lee <[email protected]> Shanavas M <[email protected]> Simon Charette <[email protected]> Simon Schmidt <[email protected]> srafehi <[email protected]> Steven Sklar <[email protected]> Tom Booth <[email protected]> Tom Clancy <[email protected]> Toni Ruža <[email protected]> tothegump <[email protected]> Victor Mireyev <[email protected]> Vikas Prasad <[email protected]> walterqian <[email protected]> Willem <[email protected]> Xiaodong <[email protected]> yywing <[email protected]>
注意: 这里是从git
的提交历史中自动生成的,因此遗憾的是并不包含那些为更重要的事情(如回答邮件列表里的问题)提供了帮助的人。
请阅读下方的重要提示,因为其中包含了一些重大更改。
支持的 Python 版本有:
- CPython 2.7
- CPython 3.4
- CPython 3.5
- CPython 3.6
- CPython 3.7
- PyPy2.7 6. (pypy2)
- PyPy3.5 6.0 (pypy3)
从此版本开始,最低要求的版本是 Kombu 4.4
新的压缩算法
Kombu 4.3 包含了一些新的可选的压缩方式:
- LZMA (在 Python 3 下可以从 stdlib 的获取,或者从向后支持的包中获取)
- Brotli (在安装了 brotli 或者 brotlipy 包的情况下可用)
- ZStandard (在安装了 zstandard 包的情况下可用)
不幸的是,我们当前的协议对复杂的 canvas 造成了巨大的负载。
在我们在 Celery 5 中迁移到解决该问题的第 3 版本的 Celery 协议之前,请使用一个新的压缩方式来作为解决办法。
从此版本开始,最低要求的版本是 Billiard 3.6
我们要求
eventlet >= 0.24.1
。如果你想要使用事件工作池,请使用如下命令安装 Celery:
$ pip install -U celery[eventlet]
一段时间以来,我们并不推荐使用
msgpack-python
包。现在我们通过使用 msgpack
替代解决了这个问题。如果你现在正在使用
MessagePack
序列化器,请卸载之前的包,并通过如下命令重新安装:$ pip uninstall msgpack-python -y
$ pip install -U celery[msgpack]
这要求安装
dnspython
包。如果你想使用 MongoDB 结果后端,请使用如下安装:
$ pip install -U celery[mongodb]
由于 py-redis 的早期版本中存在多个导致 Celery 出现问题的 bug,我们不得不将最低要求的版本提高到 3.2.0。
Redis 结果存储
由于 py-redis 的早期版本中存在多个导致 Celery 出现问题的 bug,我们不得不将最低要求的版本提高到 3.2.0。
官方的Riak客户端目前还不支持Python 3.7。
如果您使用的是 Riak 结果后端,请尝试从主分支安装客户端,或者避免升级到Python 3.7,直到解决此问题。
现在在 Python 3.7 环境下使用 Riak 作为结果后端时,我们会报出一个警告。
从此版本开始,我们正式不再支持 RabbitMQ 2.x。
2.x 最后一个版本是在 2012 年,我们不得不进行调整来正确支持 RabbitMQ 3.x 的高可用性。
如果因为某些原因,您仍在使用 RabbitMQ 2.x,我们建议您尽快进行升级,因为安全补丁也不再应用于 RabbitMQ 2.x。
从此版本开始,要求 Django 最低的版本是 1.11。
身份认证序列化器收到了完整的检查,它在之前受到了严重破坏。
我们现在使用
cryptography
替代了 pyOpenSSL
序列化器。Redis 中间人支持 SSL 地址
Redis 中间人现在已经支持 SSL 连接。
你也可以在 URL 中传递 SSL 配置参数:
rediss://localhost:3456?ssl_keyfile=keyfile.key&ssl_certfile=certificate.crt&ssl_ca_certs=ca.pem&ssl_cert_reqs=CERT_REQUIRED
可配置的事件交换机名称
在之前,事件交换机的名称是硬编码。
可配置的 Pidbox 交换机名称
在之前,Pidbox 交换机的名称是硬编码。
Redis 结果存储支持 SSL 地址
Redis 结果存储现在已经可以支持 SSL 连接了。
你也可以在 URL 中传递 SSL 的配置参数:
rediss://localhost:3456?ssl_keyfile=keyfile.key&ssl_certfile=certificate.crt&ssl_ca_certs=ca.pem&ssl_cert_reqs=CERT_REQUIRED
在结果中存储任务的扩展信息
- 任务名称
- 参数
- 关键字参数
- 职程执行任务的时间
- 重试的次数
- 队列名称或者路由键
此外,celery.app.task.update_state() 现在可以接受关键字参数,该参数允许您将自定义的数据和任务结果一起存储。
新的结果后端
当前版本引入了如下的新的结果存储:
- S3 结果存储
- ArangoDB 结果存储
- Azure Block Blob Storage 结果存储
- CosmosDB 结果存储
S3 结果存储
Amazon Simple Storage Service (Amazon S3) 是亚马逊提供的对象存储服务。
任务结果将使用如下的路径模板进行存储:
<s3_bucket>/<s3_base_path>/<key>
ArangoDB 结果存储
ArangoDB 是具有搜索功能单机多模型的数据库。后端将以如下文档的格式存储结果:
{
_key: {key},
task: {task}
}
Azure Block Blob Storage 结果后端
Azure Block Blob Storage 是微软提供的对象存储服务。
后端将使用如下的路径模板存储结果信息:
<azureblockblob_container_name>/<key>
CosmosDB 结果存储
Azure Cosmos DB是Microsoft专有的全球分布式多模型数据库服务。
后端将以如下的文档格式存储任务结果:
{
id: {key},
value: {task}
}
Cythonized 任务
现在支持了 Cythonized 的任务,你可以将使用
@task
装饰器的任务通过 Cython 生成 C 代码,一切将如同源来一样正常的工作。确认任务失败或者超时
Celery 4.3 引入了新的配置项
task_acks_on_failure_or_timeout
来允许你避免确认那些在配置 task_acks_late
设置为 True 时,出现失败或者超时的任务。调度器现在支持微妙
在使用 Celery beat 计划任务时设置的微妙值不再被忽略。
默认任务优先级
任务可以继承父类的优先级
将参数 设置为 True 可以使 Celery 的任务继承链接它的前一个任务的优先级。
示例:
c = celery.chain(
add.s(2), # priority=None
add.s(3).set(priority=5), # priority=5
add.s(4), # priority=5
add.s(5).set(priority=3), # priority=3
add.s(6), # priority=3
)
@app.task(bind=True)
def child_task(self):
pass
@app.task(bind=True)
def parent_task(self):
child_task.delay()
# child_task will also have priority=5
parent_task.apply_async(args=[], priority=5)
Chords 可以在 Eager 模式下执行
设置 Chord join 的超时时间
在之前,celery.result.GroupResult.join() 有一个固定的超时时间为 3 秒。
默认值仍是 3 秒。
Last modified 3yr ago