Commit 23e6ebba authored by João Capela's avatar João Capela
Browse files

[ADD] try except to cycles

parent 4b119df1
Pipeline #2631 passed with stage
in 1 minute and 4 seconds
......@@ -91,18 +91,18 @@ def run():
logger.info("Sending request to start to " + str(workerID))
logger.debug("Sending files: " + str(files))
logger.info(str(workerID) + starter)
res = requests.post(workerID + starter, files = files) # request worker docker to run
res = requests.post(workerID + starter, files=files) # request worker docker to run
if res.status_code != 102:
logger.error("An error occurred while starting the worker!")
mapping = checkSubmissionsStatus(mapping)
# results = os.listdir(RESULTS_PATH)
# results = os.listdir(RESULTS_PATH)
# for key in mapping.keys(): # reset workers that finished
# if mapping[key] in results:
# shutil.rmtree(RESULTS_PATH + mapping[key], ignore_errors=True)
# mapping[key] = None
# for key in mapping.keys(): # reset workers that finished
# if mapping[key] in results:
# shutil.rmtree(RESULTS_PATH + mapping[key], ignore_errors=True)
# mapping[key] = None
cleanResultsDirectory()
......@@ -115,6 +115,7 @@ def run():
check_if_update_day()
time.sleep(5)
def checkSubmissionsStatus(mapping):
status = CONFIGURATIONS.get('status')
for key in mapping.keys(): # reset workers that finished
......@@ -157,6 +158,7 @@ def checkSubmissionsStatus(mapping):
return mapping
def getNextInQueue(l):
integerList = [int(i) for i in l]
......@@ -175,14 +177,17 @@ def getNextInQueue(l):
def initializeWorkers():
handshake = CONFIGURATIONS.get('handshake')
dic = {}
time.sleep(10) #give time to initialize workers
time.sleep(10) # give time to initialize workers
for host in CONFIGURATIONS_WORKERS:
res = requests.get(host + handshake)
if res.status_code == 200:
logger.info('new worker instantiated -> ' + host)
dic[host] = None
else:
logger.error('declared worker is not running -> ' + host)
try:
res = requests.get(host + handshake)
if res.status_code == 200:
logger.info('new worker instantiated -> ' + host)
dic[host] = None
else:
logger.error('declared worker is not running -> ' + host)
except:
logger.error('This worker is not running -> ' + host)
logger.info(str(len(dic)) + " workers initialized")
......@@ -195,11 +200,15 @@ def findAvailableWorker(mapping):
print(mapping)
for key in mapping.keys():
if mapping[key] is None:
res = requests.get(key + handshake)
if res.status_code == 200:
return key
else:
logger.error('worker not responsive -> ' + key)
try:
res = requests.get(key + handshake)
if res.status_code == 200:
return key
else:
logger.error('worker not responsive -> ' + key)
except:
logger.error(key + ' Worker is dead')
return None
......@@ -236,7 +245,7 @@ def check_if_update_day():
UPDATED = True
else:
#When update day ends, boolean to false. this prevents multiple uptade orders on the same day
# When update day ends, boolean to false. this prevents multiple uptade orders on the same day
UPDATED = False
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment