Added check for good response

Signed-off-by: fly <merspieler@airmail.cc>
This commit is contained in:
fly 2021-03-09 13:09:57 +00:00
parent 3cea4bad5f
commit f2ba15a3d2

View file

@ -121,9 +121,13 @@ def api_send_status(name, status, api, token):
success = False
while not success:
response = requests.post(api, data={'auth': token, 'action': 'set', 'tile': name, 'status': status}, headers={"lAccept": "application/json", "Content-Type": "application/x-www-form-urlencoded"})
if response.ok:
success = response.json()["success"]
if not success:
print("Warning: Unable to send status " + status + " for tile " + name + ". Trying again in 60 seconds")
print("Warning: Unable to send status '" + status + "' for tile '" + name + "'. Trying again in 60 seconds")
sleep(60)
else:
print("Warning: Unable to send status '" + status + "' for tile '" + name + "'. Trying again in 60 seconds")
sleep(60)
except IOError:
print("Warning: Unable to send status " + status + " for tile " + name + ". Trying again in 60 seconds")
@ -159,6 +163,7 @@ def get_job(action, host, port, none_exit=True):
def api_get_job(action, api, token, none_exit=True):
try:
response = requests.post(api, data={'auth': token, 'action': 'get-job', 'additional-type': action}, headers={"lAccept": "application/json", "Content-Type": "application/x-www-form-urlencoded"})
if response.ok:
match = re.match(r"[ew]\d{3}[ns]\d{2}|[0-9]{1,7}|None", str(response.json()["job"]))
if match != None:
ret = match.group(0)
@ -170,9 +175,13 @@ def api_get_job(action, api, token, none_exit=True):
sleep(10)
ret = api_get_job(action, api, token, none_exit)
return ret
else:
print("Unable to get job. Retrying in 60 seconds...")
sleep(60)
ret = get_job(action, host, port, none_exit)
except IOError:
print("Unable to get job. Retrying in 10 seconds...")
sleep(10)
print("Unable to get job. Retrying in 60 seconds...")
sleep(60)
ret = get_job(action, host, port, none_exit)
return ret
@ -203,12 +212,16 @@ def api_get_status(name, api, api_token):
response = requests.post(api, data={'auth': token, 'action': 'status', 'area': name}, headers={"lAccept": "application/json", "Content-Type": "application/x-www-form-urlencoded"})
else:
response = requests.post(api, data={'auth': token, 'action': 'status', 'tile': name}, headers={"lAccept": "application/json", "Content-Type": "application/x-www-form-urlencoded"})
if response.ok:
match = re.match(r"pending|done|rebuild|skip|started|packaged", response.json()["status"])
if match != None:
return match.group(0)
else:
print("ERROR: Recived invalid state for " + name)
sys.exit(1)
else:
print("ERROR: Unable to get status.")
sys.exit(1)
except IOError:
print("ERROR: Unable to get status.")
sys.exit(1)