feature: added new setting for api command timeouts.

This commit is contained in:
Upstream Data
2023-11-24 23:19:14 -07:00
parent 78f689eb2c
commit 690d0d99df
5 changed files with 11 additions and 10 deletions

View File

@@ -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",

View File

@@ -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)

View File

@@ -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

View File

@@ -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

View File

@@ -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