amoghrajesh commented on code in PR #56762:
URL: https://github.com/apache/airflow/pull/56762#discussion_r2451202879
##########
task-sdk/src/airflow/sdk/api/client.py:
##########
@@ -812,6 +817,37 @@ def noop_handler(request: httpx.Request) -> httpx.Response:
API_SSL_CERT_PATH = conf.get("api", "ssl_cert")
+def _should_retry_api_request(exception: BaseException) -> bool:
+ """Determine if an API request should be retrie based on the exception
type."""
+ if isinstance(exception, httpx.HTTPStatusError):
+ status = exception.response.status_code
+ return status >= 500 or status == 429
+
+ # for all other httpx errors (network, timeout, connect, etc.), retry
+ if isinstance(exception, httpx.RequestError):
+ return True
+
+ return False
+
+
+def _get_retry_wait_time(retry_state) -> float:
+ """
+ Calculate wait time for retry, respecting Retry-After header on 429
responses.
+
+ For rate limit responses (429) with a Retry-After header, uses the value
from the header.
+ Otherwise, fall bacsk to exponential backoff with jitter.
+ """
+ exception = retry_state.outcome.exception()
+
+ if isinstance(exception, httpx.HTTPStatusError):
+ if exception.response.status_code == 429:
+ retry_after = exception.response.headers.get("Retry-After")
+ if retry_after and retry_after.isdigit():
+ return float(retry_after)
+
+ return wait_random_exponential(min=API_RETRY_WAIT_MIN,
max=API_RETRY_WAIT_MAX)(retry_state)
Review Comment:
Removed in latest commits
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]