6
6
7
7
import requests
8
8
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 )
13
11
14
12
_log_f = lambda x : x
15
13
16
14
17
15
class Status :
18
16
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"
33
31
}
34
32
35
33
def __init__ (self , status ):
@@ -45,7 +43,7 @@ def decode_status(self, status_long):
45
43
return self .statusMap [status_long ]
46
44
47
45
48
- class Task :
46
+ class Job :
49
47
_status : [Status , None ] = None
50
48
_uuid : [str , None ] = None
51
49
@@ -76,39 +74,39 @@ def is_finished(self) -> bool:
76
74
return self ._status == "failed" or self ._status == "deleted" or self ._status == "success"
77
75
78
76
79
- def check_for_job (task ):
77
+ def check_for_job (job ):
80
78
try :
81
- job_url = "{}/{}" .format (list_task_url , task .uuid )
79
+ job_url = "{}/{}" .format (list_job_url , job .uuid )
82
80
83
- while not task .is_finished ():
81
+ while not job .is_finished ():
84
82
response = requests .get (job_url , timeout = 500 )
85
83
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 ():
88
86
time .sleep (3 )
89
87
90
88
except requests .exceptions .RequestException as err :
91
89
return err
92
90
93
91
94
- def post_job (task , file_pth , params ):
92
+ def post_job (job , file_pth , params ):
95
93
try :
96
94
files = {'input_file' : open (file_pth , 'rb' )}
97
95
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 )
99
97
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" ]
102
100
103
101
except requests .exceptions .RequestException as err :
104
102
return err
105
103
106
104
107
- def download_results (task , extract_pth ):
108
- if task .status == "failed" :
105
+ def download_results (job , extract_pth ):
106
+ if job .status == "failed" :
109
107
return
110
108
try :
111
- output_url = "{}/{}/{}" .format (list_task_url , task .uuid , "download" )
109
+ output_url = "{}/{}/{}" .format (list_job_url , job .uuid , "download" )
112
110
113
111
response = requests .get (output_url , timeout = 5 )
114
112
response .raise_for_status ()
@@ -126,13 +124,13 @@ def download_results(task, extract_pth):
126
124
127
125
128
126
def 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" }
136
134
137
135
new_config = {}
138
136
@@ -151,46 +149,46 @@ def run_ring_api(file_pth, run_config, tmp_dir, log_f, progress_f):
151
149
152
150
_log_f = log_f
153
151
154
- task : Task = Task ()
152
+ job : Job = Job ()
155
153
156
154
file_name = os .path .basename (file_pth )
157
155
_log_f (file_pth , file_name )
158
156
159
- parameters = {"task_name" : "ring-plugin-api" ,
157
+ parameters = {"task" : "ring-plugin-api" ,
160
158
"original_name" : file_name
161
159
}
162
160
163
161
parameters .update (config_to_parameters (run_config ))
164
162
165
163
_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 ))
168
166
t_post_job .start ()
169
167
170
168
prev_progress = 0
171
169
while t_post_job .is_alive ():
172
170
progress_f (min ([prev_progress , 15 ]))
173
171
prev_progress = (prev_progress + 0.01 )
174
172
175
- t_check_job = Thread (target = check_for_job , args = (task ,))
173
+ t_check_job = Thread (target = check_for_job , args = (job ,))
176
174
t_check_job .start ()
177
175
178
176
prev_progress = 15
179
177
timer = time .time () - 5
180
178
while t_check_job .is_alive ():
181
179
if time .time () - timer > 5 :
182
180
timer = time .time ()
183
- _log_f ("Running task {}" .format (task ))
181
+ _log_f ("Running job {}" .format (job ))
184
182
185
183
progress_f (min ([prev_progress , 85 ]))
186
184
prev_progress = (prev_progress + 0.00001 )
187
185
188
- if task .status == "success" :
186
+ if job .status == "success" :
189
187
_log_f ("Computation terminated, downloading results" )
190
188
else :
191
189
_log_f ("Error in the execution of RING, please retry later or launch locally" , error = True )
192
190
193
- t_download_results = Thread (target = download_results , args = (task , tmp_dir ))
191
+ t_download_results = Thread (target = download_results , args = (job , tmp_dir ))
194
192
t_download_results .start ()
195
193
196
194
prev_progress = 85
0 commit comments