用于重试退避的芹菜配置
Celery configuration for retry backoff
我想让我的应用程序中的所有异步任务在出现任何异常时重试,并且还希望重试遵循指数退避。
@celery_app.task(autoretry_for=(Exception,))
def some_task():
...
在我的配置中我有
CELERY_TASK_ANNOTATIONS = {'*': {'max_retries': 5, 'retry_backoff': 5}}
max_retries 设置有效,现在所有任务在失败前重试 5 次。但是所有这些都会在 180 秒后重试。
我希望所有任务都遵循某种方式 retry_backoff
而不必为每个任务指定它,以便我可以随时在一个地方更改它。
为了避免在多个地方更改它,您可以做的是拥有一个全局变量,比如您将在任务注释中使用的 global_retry_backoff=5
:@celery_app.task(autoretry_for=(Exception,), retry_backoff=global_retry_backoff)
.
根据Celery documentation看来你要设置的属性是retry_backoff_max
。
Task.retry_backoff_max
A number. If retry_backoff is enabled, this option will set a maximum
delay in seconds between task autoretries. By default, this option is
set to 600, which is 10 minutes.
retry_backoff
可以是数字或布尔值,基于它的退避行为会有所不同。对于指数退避,您似乎想将其设置为真。
Task.retry_backoff
A boolean, or a number. If this option is set to
True, autoretries will be delayed following the rules of exponential
backoff. The first retry will have a delay of 1 second, the second
retry will have a delay of 2 seconds, the third will delay 4 seconds,
the fourth will delay 8 seconds, and so on. (However, this delay value
is modified by retry_jitter, if it is enabled.) If this option is set
to a number, it is used as a delay factor. For example, if this option
is set to 3, the first retry will delay 3 seconds, the second will
delay 6 seconds, the third will delay 12 seconds, the fourth will
delay 24 seconds, and so on. By default, this option is set to False,
and autoretries will not be delayed.
我想让我的应用程序中的所有异步任务在出现任何异常时重试,并且还希望重试遵循指数退避。
@celery_app.task(autoretry_for=(Exception,))
def some_task():
...
在我的配置中我有
CELERY_TASK_ANNOTATIONS = {'*': {'max_retries': 5, 'retry_backoff': 5}}
max_retries 设置有效,现在所有任务在失败前重试 5 次。但是所有这些都会在 180 秒后重试。
我希望所有任务都遵循某种方式 retry_backoff
而不必为每个任务指定它,以便我可以随时在一个地方更改它。
为了避免在多个地方更改它,您可以做的是拥有一个全局变量,比如您将在任务注释中使用的 global_retry_backoff=5
:@celery_app.task(autoretry_for=(Exception,), retry_backoff=global_retry_backoff)
.
根据Celery documentation看来你要设置的属性是retry_backoff_max
。
Task.retry_backoff_max
A number. If retry_backoff is enabled, this option will set a maximum delay in seconds between task autoretries. By default, this option is set to 600, which is 10 minutes.
retry_backoff
可以是数字或布尔值,基于它的退避行为会有所不同。对于指数退避,您似乎想将其设置为真。
Task.retry_backoff
A boolean, or a number. If this option is set to True, autoretries will be delayed following the rules of exponential backoff. The first retry will have a delay of 1 second, the second retry will have a delay of 2 seconds, the third will delay 4 seconds, the fourth will delay 8 seconds, and so on. (However, this delay value is modified by retry_jitter, if it is enabled.) If this option is set to a number, it is used as a delay factor. For example, if this option is set to 3, the first retry will delay 3 seconds, the second will delay 6 seconds, the third will delay 12 seconds, the fourth will delay 24 seconds, and so on. By default, this option is set to False, and autoretries will not be delayed.