[GitHub] [airflow] eumiro commented on a diff in pull request #33234: Refactor: Simplify code in smaller providers

2023-08-15 Thread via GitHub


eumiro commented on code in PR #33234:
URL: https://github.com/apache/airflow/pull/33234#discussion_r1295021450


##
airflow/providers/http/hooks/http.py:
##
@@ -363,8 +360,10 @@ async def run(
 else:
 raise AirflowException(f"Unexpected HTTP Method: 
{self.method}")
 
-attempt_num = 1
-while True:
+for attempt in range(1, 1 + self.retry_limit):
+if attempt > 1:
+await asyncio.sleep(self.retry_delay)

Review Comment:
   I was actually able to put it into the `except:` block.



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



[GitHub] [airflow] eumiro commented on a diff in pull request #33234: Refactor: Simplify code in smaller providers

2023-08-09 Thread via GitHub


eumiro commented on code in PR #33234:
URL: https://github.com/apache/airflow/pull/33234#discussion_r1288982279


##
airflow/providers/http/hooks/http.py:
##
@@ -340,31 +340,18 @@ async def run(
 if headers:
 _headers.update(headers)
 
-if self.base_url and not self.base_url.endswith("/") and endpoint and 
not endpoint.startswith("/"):
-url = self.base_url + "/" + endpoint
-else:
-url = (self.base_url or "") + (endpoint or "")
+url = "/".join([(self.base_url or "").rstrip("/"), (endpoint or 
"").lstrip("/")])
 
 async with aiohttp.ClientSession() as session:
-if self.method == "GET":
-request_func = session.get
-elif self.method == "POST":
-request_func = session.post
-elif self.method == "PATCH":
-request_func = session.patch
-elif self.method == "HEAD":
-request_func = session.head
-elif self.method == "PUT":
-request_func = session.put
-elif self.method == "DELETE":
-request_func = session.delete
-elif self.method == "OPTIONS":
-request_func = session.options
+if self.method in ("GET", "POST", "PATCH", "HEAD", "PUT", 
"DELETE", "OPTIONS"):
+request_func = getattr(session, self.method.lower())

Review Comment:
   You're right, it hides strings like `.get`. I'll revert it. Once we drop 
support for 3.9, we can put pattern matching 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



[GitHub] [airflow] eumiro commented on a diff in pull request #33234: Refactor: Simplify code in smaller providers

2023-08-09 Thread via GitHub


eumiro commented on code in PR #33234:
URL: https://github.com/apache/airflow/pull/33234#discussion_r1288976150


##
airflow/providers/http/hooks/http.py:
##
@@ -340,31 +340,18 @@ async def run(
 if headers:
 _headers.update(headers)
 
-if self.base_url and not self.base_url.endswith("/") and endpoint and 
not endpoint.startswith("/"):
-url = self.base_url + "/" + endpoint
-else:
-url = (self.base_url or "") + (endpoint or "")
+url = "/".join([(self.base_url or "").rstrip("/"), (endpoint or 
"").lstrip("/")])

Review Comment:
   This is nice.



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