首页 > 解决方案 > 我怎样才能让 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)


标签: pythondjangopython-requestscelery

解决方案


对于任何寻找这个答案的人

@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)


推荐阅读