feature: added new setting for api command timeouts.
This commit is contained in:
@@ -23,6 +23,7 @@ _settings = { # defaults
|
||||
"factory_get_retries": 1,
|
||||
"factory_get_timeout": 3,
|
||||
"get_data_retries": 1,
|
||||
"api_function_timeout": 5,
|
||||
"default_whatsminer_password": "admin",
|
||||
"default_innosilicon_password": "admin",
|
||||
"default_antminer_password": "root",
|
||||
|
||||
@@ -41,7 +41,7 @@ class AntminerModernWebAPI(BaseWebAPI):
|
||||
async with httpx.AsyncClient() as client:
|
||||
if parameters:
|
||||
data = await client.post(
|
||||
url, data=json.dumps(parameters), auth=auth, timeout=15 # noqa
|
||||
url, data=json.dumps(parameters), auth=auth, timeout=settings.get("api_function_timeout", 3) # noqa
|
||||
)
|
||||
else:
|
||||
data = await client.get(url, auth=auth)
|
||||
@@ -152,7 +152,7 @@ class AntminerOldWebAPI(BaseWebAPI):
|
||||
async with httpx.AsyncClient() as client:
|
||||
if parameters:
|
||||
data = await client.post(
|
||||
url, data=parameters, auth=auth, timeout=15
|
||||
url, data=parameters, auth=auth, timeout=settings.get("api_function_timeout", 3)
|
||||
)
|
||||
else:
|
||||
data = await client.get(url, auth=auth)
|
||||
|
||||
@@ -78,14 +78,14 @@ class GoldshellWebAPI(BaseWebAPI):
|
||||
response = await client.put(
|
||||
f"http://{self.ip}/mcb/{command}",
|
||||
headers={"Authorization": "Bearer " + self.jwt},
|
||||
timeout=5,
|
||||
timeout=settings.get("api_function_timeout", 5),
|
||||
json=parameters,
|
||||
)
|
||||
else:
|
||||
response = await client.get(
|
||||
f"http://{self.ip}/mcb/{command}",
|
||||
headers={"Authorization": "Bearer " + self.jwt},
|
||||
timeout=5,
|
||||
timeout=settings.get("api_function_timeout", 5),
|
||||
)
|
||||
json_data = response.json()
|
||||
return json_data
|
||||
@@ -108,7 +108,7 @@ class GoldshellWebAPI(BaseWebAPI):
|
||||
response = await client.get(
|
||||
f"http://{self.ip}/mcb/{command}",
|
||||
headers={"Authorization": "Bearer " + self.jwt},
|
||||
timeout=5,
|
||||
timeout=settings.get("api_function_timeout", 5),
|
||||
)
|
||||
json_data = response.json()
|
||||
data[command] = json_data
|
||||
|
||||
@@ -60,7 +60,7 @@ class InnosiliconWebAPI(BaseWebAPI):
|
||||
response = await client.post(
|
||||
f"http://{self.ip}/api/{command}",
|
||||
headers={"Authorization": "Bearer " + self.jwt},
|
||||
timeout=5,
|
||||
timeout=settings.get("api_function_timeout", 5),
|
||||
json=parameters,
|
||||
)
|
||||
json_data = response.json()
|
||||
@@ -96,7 +96,7 @@ class InnosiliconWebAPI(BaseWebAPI):
|
||||
response = await client.post(
|
||||
f"http://{self.ip}/api/{command}",
|
||||
headers={"Authorization": "Bearer " + self.jwt},
|
||||
timeout=5,
|
||||
timeout=settings.get("api_function_timeout", 5),
|
||||
)
|
||||
json_data = response.json()
|
||||
data[command] = json_data
|
||||
|
||||
@@ -70,21 +70,21 @@ class VNishWebAPI(BaseWebAPI):
|
||||
response = await client.post(
|
||||
f"http://{self.ip}/api/v1/{command}",
|
||||
headers={"Authorization": auth},
|
||||
timeout=5,
|
||||
timeout=settings.get("api_function_timeout", 5),
|
||||
json=parameters,
|
||||
)
|
||||
elif not parameters == {}:
|
||||
response = await client.post(
|
||||
f"http://{self.ip}/api/v1/{command}",
|
||||
headers={"Authorization": auth},
|
||||
timeout=5,
|
||||
timeout=settings.get("api_function_timeout", 5),
|
||||
json=parameters,
|
||||
)
|
||||
else:
|
||||
response = await client.get(
|
||||
f"http://{self.ip}/api/v1/{command}",
|
||||
headers={"Authorization": auth},
|
||||
timeout=5,
|
||||
timeout=settings.get("api_function_timeout", 5),
|
||||
)
|
||||
if not response.status_code == 200:
|
||||
# refresh the token, retry
|
||||
|
||||
Reference in New Issue
Block a user