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
51
common.py
51
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"})
|
||||||
success = response.json()["success"]
|
if response.ok:
|
||||||
if not success:
|
success = response.json()["success"]
|
||||||
print("Warning: Unable to send status " + status + " for tile " + name + ". Trying again in 60 seconds")
|
if not success:
|
||||||
|
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,20 +163,25 @@ 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"})
|
||||||
match = re.match(r"[ew]\d{3}[ns]\d{2}|[0-9]{1,7}|None", str(response.json()["job"]))
|
if response.ok:
|
||||||
if match != None:
|
match = re.match(r"[ew]\d{3}[ns]\d{2}|[0-9]{1,7}|None", str(response.json()["job"]))
|
||||||
ret = match.group(0)
|
if match != None:
|
||||||
if ret == "None" and none_exit:
|
ret = match.group(0)
|
||||||
print("No job got asigned. Exiting...")
|
if ret == "None" and none_exit:
|
||||||
sys.exit(0)
|
print("No job got asigned. Exiting...")
|
||||||
|
sys.exit(0)
|
||||||
|
else:
|
||||||
|
print("Recived invalid job. Retrying in 10 seconds...")
|
||||||
|
sleep(10)
|
||||||
|
ret = api_get_job(action, api, token, none_exit)
|
||||||
|
return ret
|
||||||
else:
|
else:
|
||||||
print("Recived invalid job. Retrying in 10 seconds...")
|
print("Unable to get job. Retrying in 60 seconds...")
|
||||||
sleep(10)
|
sleep(60)
|
||||||
ret = api_get_job(action, api, token, none_exit)
|
ret = get_job(action, host, port, none_exit)
|
||||||
return ret
|
|
||||||
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,11 +212,15 @@ 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"})
|
||||||
match = re.match(r"pending|done|rebuild|skip|started|packaged", response.json()["status"])
|
if response.ok:
|
||||||
if match != None:
|
match = re.match(r"pending|done|rebuild|skip|started|packaged", response.json()["status"])
|
||||||
return match.group(0)
|
if match != None:
|
||||||
|
return match.group(0)
|
||||||
|
else:
|
||||||
|
print("ERROR: Recived invalid state for " + name)
|
||||||
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
print("ERROR: Recived invalid state for " + name)
|
print("ERROR: Unable to get status.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
except IOError:
|
except IOError:
|
||||||
print("ERROR: Unable to get status.")
|
print("ERROR: Unable to get status.")
|
||||||
|
|
Loading…
Reference in a new issue