Skip to content
Snippets Groups Projects
Commit 81b668d3 authored by Gioacchino Vino's avatar Gioacchino Vino
Browse files

Reviewed scan python code

parent f27f044f
No related branches found
No related tags found
1 merge request!108Updated Python scan code
......@@ -171,30 +171,32 @@ class Task:
def __del__(self):
self.delete()
def get_progress(self) -> Tuple[str,int]:
res = self.client.get_tasks(filter_string = self.id)[0]
print(res['status'], res['progress'])
status = res['status'] # New -> Requested -> Queued -> Running -> Done
progress = int(res['progress'])# 0 0 0 0 -> 100 -1
self.status = status
self.progress = progress
return (status, progress)
def update_status(self):
task_info = self.client.get_tasks(filter_string = self.id)[0]
self.name = task_info.xpath('name/text()')[0]
self.status = task_info.xpath('status/text()')[0] # New -> Requested -> Queued -> Running -> Done
self.progress = int(task_info.xpath('progress/text()')[0])# 0 0 0 0 -> 100 -1
self.in_use = task_info.xpath('in_use/text()')[0]
try:
self.report_id = task_info.xpath('last_report/report/@id')[0]
except:
pass
def wait(self, timeout: int = 3600) -> bool:
start_time = time()
logging.debug("Waiting for scans ends the task")
while True:
status, progress = self.get_progress()
if status not in ["New","Requested","Queued","Running","Done"]: # ["Interrupted", ...]
logging.warning(f"Task in the undesired status: '{status}'")
self.update_status()
if self.status not in ["New","Requested","Queued","Running","Done"]: # ["Interrupted", ...]
logging.warning(f"Task in the undesired status: '{self.status}'")
return False
if status == "Done" and progress == -1:
if self.status == "Done" and self.progress == -1:
logging.info(f"Task completed")
return True
if time() - start_time > timeout:
logging.error("TIMEOUT during waiting for task ending")
return False
logging.debug(f"Waiting for the task ends. Now {int(time() - start_time)}s from start. Status: {status}")
logging.debug(f"Waiting for the task ends. Now {int(time() - start_time)}s from start. Status: {self.status}")
sleep(10)
def save_report(self, report_format: str, report_filename: str):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment