From 2b758a453007ed13e9fdf57744b493ad8d3c2cc7 Mon Sep 17 00:00:00 2001 From: HamadaSalhab Date: Wed, 13 Nov 2024 18:46:43 +0300 Subject: [PATCH 1/2] fix(agents-api): Add tenacity's RetryError to the list of retryable errors --- agents-api/agents_api/common/exceptions/tasks.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/agents-api/agents_api/common/exceptions/tasks.py b/agents-api/agents_api/common/exceptions/tasks.py index 78f3e967a..10fd88e39 100644 --- a/agents-api/agents_api/common/exceptions/tasks.py +++ b/agents-api/agents_api/common/exceptions/tasks.py @@ -24,6 +24,7 @@ import pydantic import requests import temporalio.exceptions +from tenacity import RetryError # 🚫 The "No Second Chances" Club - errors that we won't retry # Because sometimes, no means no! @@ -130,6 +131,9 @@ # # Database/storage related (when the database needs a nap) asyncio.TimeoutError, + # + # Tenacity exceptions (retry when retrying goes wrong lol) + RetryError, ) # HTTP status codes that say "maybe try again later?" From d20007767bd9cce0f0bcaa8c7c6312bf33efcfda Mon Sep 17 00:00:00 2001 From: HamadaSalhab Date: Wed, 13 Nov 2024 18:46:58 +0300 Subject: [PATCH 2/2] Remove duplicated code --- agents-api/agents_api/common/exceptions/tasks.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/agents-api/agents_api/common/exceptions/tasks.py b/agents-api/agents_api/common/exceptions/tasks.py index 10fd88e39..aec452f21 100644 --- a/agents-api/agents_api/common/exceptions/tasks.py +++ b/agents-api/agents_api/common/exceptions/tasks.py @@ -180,15 +180,3 @@ def is_retryable_error(error: BaseException) -> bool: # If we don't know this error, we play it safe and don't retry # (stranger danger!) return False - - # Check for specific HTTP errors that should be retried - if isinstance(error, fastapi.exceptions.HTTPException): - if error.status_code in RETRYABLE_HTTP_STATUS_CODES: - return True - - if isinstance(error, httpx.HTTPStatusError): - if error.response.status_code in RETRYABLE_HTTP_STATUS_CODES: - return True - - # If we don't know about the error, we should not retry - return False