fix: API does not suspend after 1st request
This commit is contained in:
29
src/utils.py
29
src/utils.py
@@ -1,7 +1,6 @@
|
||||
import logging
|
||||
from fastapi import Request
|
||||
import httpx
|
||||
from pprint import pprint
|
||||
from src.database import get_config_from_db
|
||||
|
||||
|
||||
@@ -22,20 +21,20 @@ async def get_data_from_ontap(request: Request, logger, endpoint: str, query_str
|
||||
logger.debug("Got the config from REDIS: %s", config)
|
||||
|
||||
results = []
|
||||
async with request.state.requests_client as _client:
|
||||
for cluster in config:
|
||||
print(f"\n\n looping, {cluster}")
|
||||
url = f"https://{cluster.hostname}/api/{endpoint}"
|
||||
if query_string:
|
||||
url += f"?{query_string}"
|
||||
try:
|
||||
logger.debug(f"Fetching data from ONTAP: {url}")
|
||||
response = await _client.get(url, auth=(cluster.username, cluster.password))
|
||||
response.raise_for_status()
|
||||
results.extend(response.json()["records"])
|
||||
except httpx.HTTPError as e:
|
||||
logger.error(f"HTTP error occurred: {e}")
|
||||
return None
|
||||
client = request.state.requests_client
|
||||
for cluster in config:
|
||||
print(f"\n\n looping, {cluster}")
|
||||
url = f"https://{cluster.hostname}/api/{endpoint}"
|
||||
if query_string:
|
||||
url += f"?{query_string}"
|
||||
try:
|
||||
logger.debug(f"Fetching data from ONTAP: {url}")
|
||||
response = await client.get(url, auth=(cluster.username, cluster.password))
|
||||
response.raise_for_status()
|
||||
results.extend(response.json()["records"])
|
||||
except httpx.HTTPError as e:
|
||||
logger.error(f"HTTP error occurred: {e}")
|
||||
return None
|
||||
return results
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user