potiuk commented on code in PR #44311: URL: https://github.com/apache/airflow/pull/44311#discussion_r1863876233
########## providers/src/airflow/providers/edge/cli/api_client.py: ########## @@ -0,0 +1,120 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +from __future__ import annotations + +import json +import logging +from datetime import datetime +from http import HTTPStatus +from pathlib import Path +from typing import TYPE_CHECKING, Any +from urllib.parse import quote, urljoin, urlparse + +import requests +import tenacity +from requests.exceptions import ConnectionError +from urllib3.exceptions import NewConnectionError + +from airflow.configuration import conf +from airflow.exceptions import AirflowException +from airflow.providers.edge.worker_api.auth import jwt_signer +from airflow.providers.edge.worker_api.datamodels import WorkerStateBody + +if TYPE_CHECKING: + from airflow.providers.edge.models.edge_worker import EdgeWorkerState + +logger = logging.getLogger(__name__) + + +class AirflowHttpException(AirflowException): + """Raise when there is a problem during an http request on the internal API decorator.""" + + def __init__(self, message: str, status_code: HTTPStatus): + super().__init__(message) + self.status_code = status_code + + +def _is_retryable_exception(exception: BaseException) -> bool: + """ + Evaluate which exception types to retry. + + This is especially demanded for cases where an application gateway or Kubernetes ingress can + not find a running instance of a webserver hosting the API (HTTP 502+504) or when the + HTTP request fails in general on network level. + + Note that we want to fail on other general errors on the webserver not to send bad requests in an endless loop. + """ + retryable_status_codes = (HTTPStatus.BAD_GATEWAY, HTTPStatus.GATEWAY_TIMEOUT) + return ( + isinstance(exception, AirflowHttpException) + and exception.status_code in retryable_status_codes + or isinstance(exception, (ConnectionError, NewConnectionError)) + ) + + +@tenacity.retry( + stop=tenacity.stop_after_attempt(10), Review Comment: Eh..... I am not really sure "make this configurable" should be in our vocabulary - and I am only half-joking here -- 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: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org