Celery:如何批量生产任务?

Celery: How to batch produce tasks?

我有一个大循环来生成任务:

for i in range(1000):
    receiver.apply_async(args=(i), kwargs={}, exchange=topic_exchange, routing_key=topic_key)

并且我发现在celery 3.X之前有一个模块celery.contrib.batches或者在celery 4.X之后有一个模块celery_batches。但是这个模块似乎不支持这样的参数。那我该怎么做呢?

我正在使用 celery 4.4.7 和 rabbitmq。

如果“批处理”是指所有任务的一小部分(块),那么您可以查看 Chunks. Instead of using chunks (they are after all made for different purpose), I suggest you use Chord if you care about results. If you do not, then just simply create a Group。一千个任务不算什么 - 我们已经 chords/groups 完成了数以万计的任务,而 Celery 可以很好地应对这种负载。