python - 我怎样才能让 celery 重试请求直到成功
问题描述
如果服务处于脱机状态,则尝试将数据发布到后端服务我希望 celery 继续发出请求直到成功
我不断收到 requests.exceptions.ConnectionError: Max retries exceeded with url
我尝试使用请求重试类,因为这不是解决方案,因为如果 celery 离线,它不会保留任何数据我正在寻找一种解决方案,其中 celery 只继续尝试
@shared_task(queue='development',autoretry_for=(Exception,ConnectionError))
def myfunction:
response = requests.post(URL),headers={"Content-Type":"application/json"},
json=obj)
解决方案
对于任何寻找这个答案的人
@shared_task(queue='development',autoretry_for=(Exception,ConnectionError))
def myfunction:
response = requests.post(URL),headers={"Content-Type":"application/json"},
json=obj)
except ConnectionError as exc:
raise myfunction.retry(exc=exc)
except Exception as exc:
raise myfunction.retry(exc=exc)
推荐阅读
- javascript - 如何实现这个 svg 动画?
- javascript - 在wordpress中单击一个后禁用多个recaptchas
- polymer - Polymer 和 LitElement 共存
- typescript - 基于接口实现类方法
- android - 我的导航视图未显示我的菜单项
- c - 在c中使用while循环查找a1z,b2y,c3x,...,...,....,nnn的斐波那契数列的程序?
- python - 如何在 cloudant-python 中选择特定字段进行查询?
- python - 在 Dask 中处理多个 csv
- php - 在 MySQL 中对通过 UNION 连接的 SUM 进行求和,并在 PHP 中使用 ECHO 显示
- python - 无法构造反向牛顿多项式