【发布时间】:2020-08-17 15:39:12
【问题描述】:
来自 celery 文档,
If you want to automatically retry on any error, simply use:
@app.task(autoretry_for=(Exception,))
def x():
...
我们如何记录它重试的异常? 如果我们有一个try-except,那么添加日志很容易,例如
@app.task(bind=True, default_retry_delay=30 * 60) # retry in 30 minutes.
def add(self, x, y):
try:
something_raising()
except Exception as exc:
logger.info('Retry for exception %s', exc)
# overrides the default delay to retry after 1 minute
raise self.retry(exc=exc, countdown=60)
但我想使用自动重试,这样我就可以利用自动重试附带的 celery 重试退避,而不是使用 try-except 实现我自己的倒计时。请帮忙。
【问题讨论】:
标签: python python-3.x celery django-celery celery-task