Skip to content

Commit

Permalink
Add timeout to requests calls (#1)
Browse files Browse the repository at this point in the history
Co-authored-by: pixeebot[bot] <104101892+pixeebot[bot]@users.noreply.github.com>
  • Loading branch information
pixeebot[bot] authored Aug 23, 2024
1 parent b245597 commit 16973e0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions backend/utils/request/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ def make_http_request(
"""Generic helper function to help make a HTTP request."""
try:
if verb == HTTPMethod.GET:
response = pyrequests.get(url, params=params, headers=headers)
response = pyrequests.get(url, params=params, headers=headers, timeout=60)
elif verb == HTTPMethod.POST:
response = pyrequests.post(url, json=data, params=params, headers=headers)
response = pyrequests.post(url, json=data, params=params, headers=headers, timeout=60)
elif verb == HTTPMethod.DELETE:
response = pyrequests.delete(url, params=params, headers=headers)
response = pyrequests.delete(url, params=params, headers=headers, timeout=60)
else:
raise ValueError("Invalid HTTP verb. Supported verbs: GET, POST, DELETE")

Expand Down
6 changes: 3 additions & 3 deletions prompt-service/src/unstract/prompt_service/utils/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ def make_http_request(
"""Generic helper function to help make a HTTP request."""
try:
if verb == HTTPMethod.GET:
response = pyrequests.get(url, params=params, headers=headers)
response = pyrequests.get(url, params=params, headers=headers, timeout=60)
elif verb == HTTPMethod.POST:
response = pyrequests.post(url, json=data, params=params, headers=headers)
response = pyrequests.post(url, json=data, params=params, headers=headers, timeout=60)
elif verb == HTTPMethod.DELETE:
response = pyrequests.delete(url, params=params, headers=headers)
response = pyrequests.delete(url, params=params, headers=headers, timeout=60)
else:
raise ValueError("Invalid HTTP verb. Supported verbs: GET, POST, DELETE")

Expand Down
4 changes: 2 additions & 2 deletions unstract/tool-sandbox/src/unstract/tool_sandbox/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def make_get_request(
"""
url = f"{self.base_url}{endpoint}"
params = {"image_name": image_name, "image_tag": image_tag}
response = requests.get(url, params=params)
response = requests.get(url, params=params, timeout=60)
result: Optional[dict[str, Any]] = None
if response.status_code == 200:
result = response.json()
Expand Down Expand Up @@ -91,7 +91,7 @@ def call_tool_handler(
settings,
)

response = requests.post(url, json=data)
response = requests.post(url, json=data, timeout=60)
result: Optional[dict[str, Any]] = None
if response.status_code == 200:
result = response.json()
Expand Down

0 comments on commit 16973e0

Please sign in to comment.