From cdab352bc8c80f290263acac0a1de5b95b4c18e4 Mon Sep 17 00:00:00 2001 From: Gabriel Luiz Freitas Almeida Date: Thu, 15 Aug 2024 10:50:11 -0300 Subject: [PATCH] feat: Add timeout parameter to HTTP request in StoreService. (#3362) --- .../base/langflow/services/store/service.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/backend/base/langflow/services/store/service.py b/src/backend/base/langflow/services/store/service.py index a1b221b63..e0d3649d0 100644 --- a/src/backend/base/langflow/services/store/service.py +++ b/src/backend/base/langflow/services/store/service.py @@ -97,6 +97,7 @@ class StoreService(Service): "last_tested_version", "private", ] + self.timeout = 30 # Create a context manager that will use the api key to # get the user data and all requests inside the context manager @@ -129,7 +130,7 @@ class StoreService(Service): headers = {} async with httpx.AsyncClient() as client: try: - response = await client.get(url, headers=headers, params=params) + response = await client.get(url, headers=headers, params=params, timeout=self.timeout) response.raise_for_status() except HTTPError as exc: raise exc @@ -151,7 +152,9 @@ class StoreService(Service): try: headers = {"Authorization": f"Bearer {api_key}"} async with httpx.AsyncClient() as client: - response = await client.post(webhook_url, headers=headers, json={"component_id": str(component_id)}) + response = await client.post( + webhook_url, headers=headers, json={"component_id": str(component_id)}, timeout=self.timeout + ) response.raise_for_status() return response.json() except HTTPError as exc: @@ -359,7 +362,9 @@ class StoreService(Service): # response = httpx.post(self.components_url, headers=headers, json=component_dict) # response.raise_for_status() async with httpx.AsyncClient() as client: - response = await client.post(self.components_url, headers=headers, json=component_dict) + response = await client.post( + self.components_url, headers=headers, json=component_dict, timeout=self.timeout + ) response.raise_for_status() component = response.json()["data"] return CreateComponentResponse(**component) @@ -394,7 +399,7 @@ class StoreService(Service): # response.raise_for_status() async with httpx.AsyncClient() as client: response = await client.patch( - self.components_url + f"/{component_id}", headers=headers, json=component_dict + self.components_url + f"/{component_id}", headers=headers, json=component_dict, timeout=self.timeout ) response.raise_for_status() component = response.json()["data"] @@ -463,6 +468,7 @@ class StoreService(Service): self.like_webhook_url, json={"component_id": str(component_id)}, headers=headers, + timeout=self.timeout, ) response.raise_for_status() if response.status_code == 200: