Skip to content

Commit 40ebc27

Browse files
authored
Retry and Timeout Changes for espminer (#340)
* Retry and Timeout Fixes for espminer * Build check fix
1 parent b8ae238 commit 40ebc27

File tree

1 file changed

+28
-26
lines changed

1 file changed

+28
-26
lines changed

pyasic/web/espminer.py

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,34 +20,36 @@ async def send_command(
2020
**parameters: Any,
2121
) -> dict:
2222
url = f"http://{self.ip}:{self.port}/api/{command}"
23-
try:
24-
async with httpx.AsyncClient(
25-
transport=settings.transport(),
26-
) as client:
27-
if parameters.get("post", False):
28-
parameters.pop("post")
29-
data = await client.post(
30-
url,
31-
timeout=settings.get("api_function_timeout", 3),
32-
json=parameters,
33-
)
34-
elif parameters.get("patch", False):
35-
parameters.pop("patch")
36-
data = await client.patch(
37-
url,
38-
timeout=settings.get("api_function_timeout", 3),
39-
json=parameters,
40-
)
41-
else:
42-
data = await client.get(url)
43-
except httpx.HTTPError:
44-
pass
45-
else:
46-
if data.status_code == 200:
23+
async with httpx.AsyncClient(transport=settings.transport()) as client:
24+
for _ in range(settings.get("get_data_retries", 1)):
4725
try:
48-
return data.json()
49-
except json.decoder.JSONDecodeError:
26+
if parameters.get("post", False):
27+
parameters.pop("post")
28+
data = await client.post(
29+
url,
30+
timeout=settings.get("api_function_timeout", 3),
31+
json=parameters,
32+
)
33+
elif parameters.get("patch", False):
34+
parameters.pop("patch")
35+
data = await client.patch(
36+
url,
37+
timeout=settings.get("api_function_timeout", 3),
38+
json=parameters,
39+
)
40+
else:
41+
data = await client.get(
42+
url,
43+
timeout=settings.get("api_function_timeout", 5),
44+
)
45+
except httpx.HTTPError:
5046
pass
47+
else:
48+
if data.status_code == 200:
49+
try:
50+
return data.json()
51+
except json.decoder.JSONDecodeError:
52+
pass
5153

5254
async def multicommand(
5355
self, *commands: str, ignore_errors: bool = False, allow_warning: bool = True

0 commit comments

Comments
 (0)