如何重试所有因数据库错误而失败的芹菜任务?

How to retry all celery tasks that fail due to database errors?

我们的 django 代码库中有多个共享任务,它们从数据库中获取数据并进行操作。是否可以包含重试 "all" 失败任务的芹菜配置,而不是在每个单独的任务

中添加 "try-catch"

考虑使用 autoretry_for 选项,参见 celery docs

UPD.
指定后不为每个任务提供选项可能会更方便。不幸的是,当时 autoretry_for 只能作为任务装饰器参数传递,但有一种函数式方法可以做到这一点

from functools import partial
from celery import shared_task

shared_task = partial(shared_task, autoretry_for=(RuntimeError,))))