Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion dkg/providers/node/async_node_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ def __init__(
endpoint_uri: URI | str,
api_version: str = "v1",
auth_token: str | None = None,
timeout: int = 60, # timeout in seconds
):
super().__init__(endpoint_uri, api_version, auth_token)
self.timeout = timeout

async def make_request(
self,
Expand All @@ -42,7 +44,9 @@ async def make_request(
) -> NodeResponseDict:
url = f"{self.url}/{path}"

async with aiohttp.ClientSession() as session:
timeout_config = aiohttp.ClientTimeout(total=self.timeout)

async with aiohttp.ClientSession(timeout=timeout_config) as session:
try:
if method == HTTPRequestMethod.GET:
async with session.get(
Expand Down
10 changes: 8 additions & 2 deletions dkg/providers/node/node_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ def __init__(
endpoint_uri: URI | str,
api_version: str = "v1",
auth_token: str | None = None,
timeout: tuple[int, int] = (30, 60), # (connect_timeout, read_timeout)
):
super().__init__(endpoint_uri, api_version, auth_token)
self.timeout = timeout

def make_request(
self,
Expand All @@ -45,9 +47,13 @@ def make_request(

try:
if method == HTTPRequestMethod.GET:
response = requests.get(url, params=params, headers=self.headers)
response = requests.get(
url, params=params, headers=self.headers, timeout=self.timeout
)
elif method == HTTPRequestMethod.POST:
response = requests.post(url, json=data, headers=self.headers)
response = requests.post(
url, json=data, headers=self.headers, timeout=self.timeout
)
else:
raise HTTPRequestMethodNotSupported(
f"{method.name} method isn't supported"
Expand Down