Mercurial > repos > fabio > sbtas_se
comparison query.py @ 18:dd3c4fd64402 draft
Uploaded 20180223
| author | fabio | 
|---|---|
| date | Fri, 23 Feb 2018 13:21:14 -0500 | 
| parents | e780b47013df | 
| children | 
   comparison
  equal
  deleted
  inserted
  replaced
| 17:c1b3f3510219 | 18:dd3c4fd64402 | 
|---|---|
| 8 | 8 | 
| 9 #### NN14 #### | 9 #### NN14 #### | 
| 10 SERVICE_URL = "http://nn14.galaxyproject.org:8080/"; | 10 SERVICE_URL = "http://nn14.galaxyproject.org:8080/"; | 
| 11 #service_url = "http://127.0.0.1:8082/"; | 11 #service_url = "http://127.0.0.1:8082/"; | 
| 12 QUERY_URL = SERVICE_URL+"tree/0/query"; | 12 QUERY_URL = SERVICE_URL+"tree/0/query"; | 
| 13 STATUS_URL = SERVICE_URL+"status/<task_id>"; | 13 STATUS_URL = SERVICE_URL+"status/<query_id>"; | 
| 14 ############## | 14 ############## | 
| 15 # query delay in seconds | 15 # query delay in seconds | 
| 16 QUERY_DELAY = 30; | 16 QUERY_DELAY = 30; | 
| 17 ############## | 17 ############## | 
| 18 | 18 | 
| 46 #print(str(req.content)+"\n\n"); | 46 #print(str(req.content)+"\n\n"); | 
| 47 if resp_code == requests.codes.ok: | 47 if resp_code == requests.codes.ok: | 
| 48 resp_content = str(req.content); | 48 resp_content = str(req.content); | 
| 49 # convert out to json | 49 # convert out to json | 
| 50 json_content = json.loads(resp_content); | 50 json_content = json.loads(resp_content); | 
| 51 # retrieve task id | 51 # retrieve query id | 
| 52 task_id = json_content['task_id']; | 52 query_id = json_content['query_id']; | 
| 53 task_processed = False; | 53 query_processed = False; | 
| 54 # results json content | 54 # results json content | 
| 55 json_status_content = None; | 55 json_status_content = None; | 
| 56 while task_processed is False: | 56 while query_processed is False: | 
| 57 # create a new session | 57 # create a new session | 
| 58 session = requests.Session(); | 58 session = requests.Session(); | 
| 59 # make a synchronous get request to the status route | 59 # make a synchronous get request to the status route | 
| 60 status_query_url = STATUS_URL.replace("<task_id>", task_id); | 60 status_query_url = STATUS_URL.replace("<query_id>", query_id); | 
| 61 status_req = session.get(status_query_url); | 61 status_req = session.get(status_query_url); | 
| 62 status_resp_content = str(status_req.content); | 62 status_resp_content = str(status_req.content); | 
| 63 #print(status_resp_content+"\n\n"); | 63 #print(status_resp_content+"\n\n"); | 
| 64 # convert out to json | 64 # convert out to json | 
| 65 json_status_content = json.loads(status_resp_content); | 65 json_status_content = json.loads(status_resp_content); | 
| 66 # take a look at the state | 66 # take a look at the state | 
| 67 # state attribute is always available | 67 # state attribute is always available | 
| 68 if json_status_content['state'] == 'SUCCESS': | 68 if json_status_content['state'] == 'SUCCESS': | 
| 69 task_processed = True; | 69 query_processed = True; | 
| 70 break; | 70 break; | 
| 71 elif json_status_content['state'] in ['FAILURE', 'REVOKED']: | 71 elif json_status_content['state'] in ['FAILURE', 'REVOKED']: | 
| 72 return raiseException( ERR_EXIT_CODE, "Task ID: "+str(task_id)+"\nTask status: "+str(json_status_content['state']), output_dir_path, str(options.errorfile) ); | 72 return raiseException( ERR_EXIT_CODE, "Query ID: "+str(query_id)+"\nQuery status: "+str(json_status_content['state']), output_dir_path, str(options.errorfile) ); | 
| 73 else: | 73 else: | 
| 74 time.sleep(QUERY_DELAY); # in seconds | 74 time.sleep(QUERY_DELAY); # in seconds | 
| 75 | 75 | 
| 76 out_file_format = "tabular"; | 76 out_file_format = "tabular"; | 
| 77 for block in json_status_content['results']: | 77 for block in json_status_content['results']: | 
