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