diff --git a/common.py b/common.py index 4c75027..d585deb 100644 --- a/common.py +++ b/common.py @@ -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"}) - success = response.json()["success"] - if not success: - print("Warning: Unable to send status " + status + " for tile " + name + ". Trying again in 60 seconds") + 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") + 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,20 +163,25 @@ 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"}) - 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) - if ret == "None" and none_exit: - print("No job got asigned. Exiting...") - sys.exit(0) + 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) + if ret == "None" and none_exit: + 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: - print("Recived invalid job. Retrying in 10 seconds...") - sleep(10) - ret = api_get_job(action, api, token, none_exit) - return ret + 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,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"}) else: 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 match != None: - return match.group(0) + 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: Recived invalid state for " + name) + print("ERROR: Unable to get status.") sys.exit(1) except IOError: print("ERROR: Unable to get status.")