Added check for good response
Signed-off-by: fly <merspieler@airmail.cc>
This commit is contained in:
parent
3cea4bad5f
commit
f2ba15a3d2
1 changed files with 32 additions and 19 deletions
19
common.py
19
common.py
|
@ -121,9 +121,13 @@ def api_send_status(name, status, api, token):
|
||||||
success = False
|
success = False
|
||||||
while not success:
|
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"})
|
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"]
|
success = response.json()["success"]
|
||||||
if not 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)
|
sleep(60)
|
||||||
except IOError:
|
except IOError:
|
||||||
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")
|
||||||
|
@ -159,6 +163,7 @@ def get_job(action, host, port, none_exit=True):
|
||||||
def api_get_job(action, api, token, none_exit=True):
|
def api_get_job(action, api, token, none_exit=True):
|
||||||
try:
|
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"})
|
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"]))
|
match = re.match(r"[ew]\d{3}[ns]\d{2}|[0-9]{1,7}|None", str(response.json()["job"]))
|
||||||
if match != None:
|
if match != None:
|
||||||
ret = match.group(0)
|
ret = match.group(0)
|
||||||
|
@ -170,9 +175,13 @@ def api_get_job(action, api, token, none_exit=True):
|
||||||
sleep(10)
|
sleep(10)
|
||||||
ret = api_get_job(action, api, token, none_exit)
|
ret = api_get_job(action, api, token, none_exit)
|
||||||
return ret
|
return ret
|
||||||
|
else:
|
||||||
|
print("Unable to get job. Retrying in 60 seconds...")
|
||||||
|
sleep(60)
|
||||||
|
ret = get_job(action, host, port, none_exit)
|
||||||
except IOError:
|
except IOError:
|
||||||
print("Unable to get job. Retrying in 10 seconds...")
|
print("Unable to get job. Retrying in 60 seconds...")
|
||||||
sleep(10)
|
sleep(60)
|
||||||
ret = get_job(action, host, port, none_exit)
|
ret = get_job(action, host, port, none_exit)
|
||||||
return ret
|
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"})
|
response = requests.post(api, data={'auth': token, 'action': 'status', 'area': name}, headers={"lAccept": "application/json", "Content-Type": "application/x-www-form-urlencoded"})
|
||||||
else:
|
else:
|
||||||
response = requests.post(api, data={'auth': token, 'action': 'status', 'tile': name}, headers={"lAccept": "application/json", "Content-Type": "application/x-www-form-urlencoded"})
|
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"])
|
match = re.match(r"pending|done|rebuild|skip|started|packaged", response.json()["status"])
|
||||||
if match != None:
|
if match != None:
|
||||||
return match.group(0)
|
return match.group(0)
|
||||||
else:
|
else:
|
||||||
print("ERROR: Recived invalid state for " + name)
|
print("ERROR: Recived invalid state for " + name)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
print("ERROR: Unable to get status.")
|
||||||
|
sys.exit(1)
|
||||||
except IOError:
|
except IOError:
|
||||||
print("ERROR: Unable to get status.")
|
print("ERROR: Unable to get status.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
Loading…
Reference in a new issue