该文档很少提及priority
属性。一份罕见的文档参考资料如下:
priority (int): The task priority, a number between 0 and 9.
Defaults to the :attr:`priority` attribute.
(Ref: http://docs.celeryproject.org/en/latest/_modules/celery/app/task.html#Task.apply_async http://docs.celeryproject.org/en/latest/_modules/celery/app/task.html#Task.apply_async )
但是,如果您转到下一页的底部 -http://docs.celeryproject.org/en/latest/userguide/calling.html http://docs.celeryproject.org/en/latest/userguide/calling.html- 你会看见:
优先事项
0 到 255 之间的数字,其中 255 是最高优先级。
支持:RabbitMQ、Redis(优先级反转,0 最高)。
这两条信息相互矛盾。另外,我认为文档字符串是最新的......
问题是哪一个是相关的,更重要的是:优先级是如何排序的——priority=0 是否意味着最高优先级?或者这取决于后端,正如文档页面所说......
我还为此创建了一个 GitHub 问题 -https://github.com/celery/celery/issues/4599 https://github.com/celery/celery/issues/4599
Update 1:我在 v4.0 的 kombu 变更日志中找到了以下内容(http://docs.celeryproject.org/projects/kombu/en/latest/changelog.html http://docs.celeryproject.org/projects/kombu/en/latest/changelog.html):
Redis:优先级 0 现在最低,9 最高。 (向后不兼容)
这与 AMQP 中优先级的工作方式相匹配。
修复由 Alex Koshelev 贡献。