66
77import requests
88
9- scheduler_url = "https://scheduler.biocomputingup.it"
10- list_task_url = "{}/task/" .format (scheduler_url )
11- list_script_url = "{}/script/" .format (scheduler_url )
12- list_params_url = "{}/params/" .format (scheduler_url )
9+ drmaatic_url = "https://drmaatic.biocomputingup.it"
10+ list_job_url = "{}/job/" .format (drmaatic_url )
1311
1412_log_f = lambda x : x
1513
1614
1715class Status :
1816 statusMap = {
19- "task has been rejected from the ws" : "failed" ,
20- "task has been received from the ws" : "pending" ,
21- "task has been created and sent to the DRM" : "pending" ,
22- "process status cannot be determined" : "pending" ,
23- "job is queued and active" : "running" ,
24- "job is queued and in system hold" : "running" ,
25- "job is queued and in user hold" : "running" ,
26- "job is queued and in user and system hold" : "running" ,
27- "job is running" : "running" ,
28- "job is system suspended" : "pending" ,
29- "job is user suspended" : "pending" ,
30- "job finished normally" : "success" ,
31- "job finished, but failed" : "failed" ,
32- "job has been deleted" : "deleted"
17+ "job has been rejected from the ws" : "failed" ,
18+ "job has been received from the ws" : "pending" ,
19+ "job has been created and sent to the DRM" : "pending" ,
20+ "process status cannot be determined" : "pending" ,
21+ "job is queued and active" : "running" ,
22+ "job is queued and in system hold" : "running" ,
23+ "job is queued and in user hold" : "running" ,
24+ "job is queued and in user and system hold" : "running" ,
25+ "job is running" : "running" ,
26+ "job is system suspended" : "pending" ,
27+ "job is user suspended" : "pending" ,
28+ "job finished normally" : "success" ,
29+ "job finished, but failed" : "failed" ,
30+ "job has been deleted" : "deleted"
3331 }
3432
3533 def __init__ (self , status ):
@@ -45,7 +43,7 @@ def decode_status(self, status_long):
4543 return self .statusMap [status_long ]
4644
4745
48- class Task :
46+ class Job :
4947 _status : [Status , None ] = None
5048 _uuid : [str , None ] = None
5149
@@ -76,39 +74,39 @@ def is_finished(self) -> bool:
7674 return self ._status == "failed" or self ._status == "deleted" or self ._status == "success"
7775
7876
79- def check_for_job (task ):
77+ def check_for_job (job ):
8078 try :
81- job_url = "{}/{}" .format (list_task_url , task .uuid )
79+ job_url = "{}/{}" .format (list_job_url , job .uuid )
8280
83- while not task .is_finished ():
81+ while not job .is_finished ():
8482 response = requests .get (job_url , timeout = 500 )
8583 response .raise_for_status ()
86- task .status = response .json ()["status" ]
87- if not task .is_finished ():
84+ job .status = response .json ()["status" ]
85+ if not job .is_finished ():
8886 time .sleep (3 )
8987
9088 except requests .exceptions .RequestException as err :
9189 return err
9290
9391
94- def post_job (task , file_pth , params ):
92+ def post_job (job , file_pth , params ):
9593 try :
9694 files = {'input_file' : open (file_pth , 'rb' )}
9795
98- response = requests .post (list_task_url , files = files , data = params , timeout = 10000 )
96+ response = requests .post (list_job_url , files = files , data = params , timeout = 10000 )
9997 response .raise_for_status ()
100- task .uuid = response .json ()["uuid" ]
101- task .status = response .json ()["status" ]
98+ job .uuid = response .json ()["uuid" ]
99+ job .status = response .json ()["status" ]
102100
103101 except requests .exceptions .RequestException as err :
104102 return err
105103
106104
107- def download_results (task , extract_pth ):
108- if task .status == "failed" :
105+ def download_results (job , extract_pth ):
106+ if job .status == "failed" :
109107 return
110108 try :
111- output_url = "{}/{}/{}" .format (list_task_url , task .uuid , "download" )
109+ output_url = "{}/{}/{}" .format (list_job_url , job .uuid , "download" )
112110
113111 response = requests .get (output_url , timeout = 5 )
114112 response .raise_for_status ()
@@ -126,13 +124,13 @@ def download_results(task, extract_pth):
126124
127125
128126def config_to_parameters (config ):
129- convert = {"-g" : "seq_sep" ,
130- "-o" : "len_salt" ,
131- "-s" : "len_ss" ,
132- "-k" : "len_pipi" ,
133- "-a" : "len_pica" ,
134- "-b" : "len_hbond" ,
135- "-w" : "len_vdw" }
127+ convert = {"-g" : "seq_sep" ,
128+ "-o" : "len_salt" ,
129+ "-s" : "len_ss" ,
130+ "-k" : "len_pipi" ,
131+ "-a" : "len_pica" ,
132+ "-b" : "len_hbond" ,
133+ "-w" : "len_vdw" }
136134
137135 new_config = {}
138136
@@ -151,46 +149,46 @@ def run_ring_api(file_pth, run_config, tmp_dir, log_f, progress_f):
151149
152150 _log_f = log_f
153151
154- task : Task = Task ()
152+ job : Job = Job ()
155153
156154 file_name = os .path .basename (file_pth )
157155 _log_f (file_pth , file_name )
158156
159- parameters = {"task_name" : "ring-plugin-api" ,
157+ parameters = {"task" : "ring-plugin-api" ,
160158 "original_name" : file_name
161159 }
162160
163161 parameters .update (config_to_parameters (run_config ))
164162
165163 _log_f ("Remote RING generation started" )
166- _log_f ("Sending task to remote server" )
167- t_post_job = Thread (target = post_job , args = (task , file_pth , parameters ))
164+ _log_f ("Sending job to remote server" )
165+ t_post_job = Thread (target = post_job , args = (job , file_pth , parameters ))
168166 t_post_job .start ()
169167
170168 prev_progress = 0
171169 while t_post_job .is_alive ():
172170 progress_f (min ([prev_progress , 15 ]))
173171 prev_progress = (prev_progress + 0.01 )
174172
175- t_check_job = Thread (target = check_for_job , args = (task ,))
173+ t_check_job = Thread (target = check_for_job , args = (job ,))
176174 t_check_job .start ()
177175
178176 prev_progress = 15
179177 timer = time .time () - 5
180178 while t_check_job .is_alive ():
181179 if time .time () - timer > 5 :
182180 timer = time .time ()
183- _log_f ("Running task {}" .format (task ))
181+ _log_f ("Running job {}" .format (job ))
184182
185183 progress_f (min ([prev_progress , 85 ]))
186184 prev_progress = (prev_progress + 0.00001 )
187185
188- if task .status == "success" :
186+ if job .status == "success" :
189187 _log_f ("Computation terminated, downloading results" )
190188 else :
191189 _log_f ("Error in the execution of RING, please retry later or launch locally" , error = True )
192190
193- t_download_results = Thread (target = download_results , args = (task , tmp_dir ))
191+ t_download_results = Thread (target = download_results , args = (job , tmp_dir ))
194192 t_download_results .start ()
195193
196194 prev_progress = 85
0 commit comments