@@ -5,7 +5,7 @@ class Job():
55
66 def __init__ (self ,
77 client ,
8- job_dict = None ):
8+ job_dict = None ):
99
1010 self .client = client
1111
@@ -36,11 +36,11 @@ def __init__(self,
3636 self .attached_directories_dict = None
3737
3838 self .refresh_from_dict (
39- job_dict = job_dict )
39+ job_dict = job_dict )
4040
4141 def refresh_from_dict (
4242 self ,
43- job_dict = None ):
43+ job_dict = None ):
4444
4545 if not job_dict :
4646 return
@@ -51,7 +51,7 @@ def refresh_from_dict(
5151 def __repr__ (self ):
5252 return str (self .serialize ())
5353
54- def __add_directory_to_job (self , directory : Directory , mode = 'sync' ):
54+ def __add_directory_to_job (self , directory : Directory , mode = 'sync' ):
5555 """
5656
5757 :param directories: Array of directories Objects
@@ -67,7 +67,7 @@ def __add_directory_to_job(self, directory: Directory, mode='sync'):
6767 )
6868 return self .attached_directories
6969
70- def attach_directories (self , directories , mode = 'sync' , override_existing = False ):
70+ def attach_directories (self , directories , mode = 'sync' , override_existing = False ):
7171 """
7272 Attaches directories to a job.
7373 :param directories: Array of directories Objects
@@ -96,7 +96,7 @@ def attach_directories(self, directories, mode='sync', override_existing=False):
9696 data ['job_id' ] = self .id
9797 response = self .client .session .post (
9898 self .client .host + endpoint ,
99- json = data )
99+ json = data )
100100
101101 self .client .handle_errors (response )
102102
@@ -139,23 +139,23 @@ def serialize(self):
139139 }
140140
141141 def new (self ,
142- name = None ,
143- instance_type = None ,
144- share = "project" ,
145- job_type = "Normal" ,
142+ name = None ,
143+ instance_type = None ,
144+ share = "project" ,
145+ job_type = "Normal" ,
146146 label_schema_id = None ,
147- permission = None ,
148- field = None ,
149- category = None ,
150- review_by_human_freqeuncy = None ,
151- label_mode = None ,
152- passes_per_file = None ,
153- guide = None ,
154- launch_datetime = None ,
155- sync_directories = [],
156- single_copy_directories = [],
147+ permission = None ,
148+ field = None ,
149+ category = None ,
150+ review_by_human_freqeuncy = None ,
151+ label_mode = None ,
152+ passes_per_file = None ,
153+ guide = None ,
154+ launch_datetime = None ,
155+ sync_directories = [],
156+ single_copy_directories = [],
157157 members_list_ids = [],
158- auto_launch = True ,
158+ auto_launch = True ,
159159 tag_list = [],
160160 ):
161161 """
@@ -174,7 +174,7 @@ def new(self,
174174 # QUESTION create job object eariler instead of after response?
175175 if len (members_list_ids ) == 0 :
176176 raise ValueError ('Please provide at least one member_id in members_list_ids.' )
177- job = Job (client = self .client )
177+ job = Job (client = self .client )
178178
179179 if label_schema_id is None :
180180 if self .client .label_schema_list :
@@ -201,10 +201,10 @@ def new(self,
201201 'Please provide at least one attached directory to the job in either sync_directories param or single_copy_directories' )
202202
203203 for dir in sync_directories :
204- job .__add_directory_to_job (directory = dir , mode = 'sync' )
204+ job .__add_directory_to_job (directory = dir , mode = 'sync' )
205205
206206 for dir in single_copy_directories :
207- job .__add_directory_to_job (directory = dir , mode = 'sync' )
207+ job .__add_directory_to_job (directory = dir , mode = 'sync' )
208208
209209 job .attached_directories_dict = {
210210 'attached_directories_list' : job .attached_directories
@@ -214,7 +214,7 @@ def new(self,
214214
215215 response = self .client .session .post (
216216 self .client .host + endpoint ,
217- json = job .serialize ())
217+ json = job .serialize ())
218218
219219 self .client .handle_errors (response )
220220
@@ -225,7 +225,7 @@ def new(self,
225225 job .id = data ["job" ]["id" ]
226226
227227 if guide :
228- job .guide_update (guide = guide )
228+ job .guide_update (guide = guide )
229229
230230 if auto_launch :
231231 endpoint_launch = "/api/v1/job/launch" .format (self .client .project_string_id )
@@ -236,35 +236,42 @@ def new(self,
236236 })
237237 self .client .handle_errors (response )
238238
239-
240-
241239 return job
242240
243-
244- def list ( self ,
245- limit = 10 ,
246- status = "All" ):
241+ def list ( self ,
242+ limit = 10 ,
243+ status = "All" ,
244+ tags = [] ):
247245
248246 # Example usage print(project.job.list().json())
249-
247+ tag_id_list = None
248+ if len (tags ) > 0 :
249+ # fetch tag id list
250+ tag_path = f'/api/v1/project/{ self .client .project_string_id } /tags/list'
251+ response_tags = self .client .session .get (self .client .host + tag_path )
252+ tag_list = response_tags .json ()['tag_list' ]
253+ tag_id_list = []
254+ for elm in tag_list :
255+ if elm ['name' ] in tags :
256+ tag_id_list .append (elm ['id' ])
250257 endpoint = "/api/v1/job/list"
251-
252- request_json_body = {"metadata" :
258+ request_json_body = {"metadata" :
253259 {
254- "limit" : limit ,
255- "status" : status ,
256- "project_string_id" : self .client .project_string_id
260+ "limit" : limit ,
261+ "data_mode" : "with_tags" ,
262+ "status" : status ,
263+ "tag_list" : tag_id_list ,
264+ "project_string_id" : self .client .project_string_id
257265 }
258266 }
259267
260268 response = self .client .session .post (
261- self .client .host + endpoint ,
262- json = request_json_body )
269+ self .client .host + endpoint ,
270+ json = request_json_body )
263271
264272 self .client .handle_errors (response )
265-
266- return response
267-
273+ result = response .json ()
274+ return result ['Job_list' ]
268275
269276 def launch (
270277 self
@@ -288,7 +295,7 @@ def launch(
288295
289296 response = self .client .session .post (
290297 self .client .host + endpoint ,
291- json = request )
298+ json = request )
292299
293300 self .client .handle_errors (response )
294301
@@ -303,8 +310,8 @@ def launch(
303310 def guide_update (
304311 self ,
305312 guide ,
306- kind = "default" ,
307- action = "update"
313+ kind = "default" ,
314+ action = "update"
308315 ):
309316 """
310317
@@ -329,7 +336,7 @@ def guide_update(
329336 'update_or_remove' : action }
330337
331338 response = self .client .session .post (self .client .host + endpoint ,
332- json = update_dict )
339+ json = update_dict )
333340
334341 self .client .handle_errors (response )
335342
@@ -347,7 +354,7 @@ def get_by_id(
347354 """
348355 """
349356
350- job = Job (client = self .client )
357+ job = Job (client = self .client )
351358 job .id = id
352359
353360 job .refresh_info ()
@@ -356,13 +363,13 @@ def get_by_id(
356363
357364 def generate_export (
358365 self ,
359- kind = 'Annotations' ,
360- return_type = "data" ,
361- source = "job" ,
362- masks = False ,
363- directory_id = None ,
364- wait_for_export_generation = True ,
365- ann_is_complete = None # Bool. None=='all', True=='complete' tasks only
366+ kind = 'Annotations' ,
367+ return_type = "data" ,
368+ source = "job" ,
369+ masks = False ,
370+ directory_id = None ,
371+ wait_for_export_generation = True ,
372+ ann_is_complete = None # Bool. None=='all', True=='complete' tasks only
366373 ):
367374 """
368375
@@ -400,7 +407,7 @@ def generate_export(
400407 }
401408
402409 response = self .client .session .post (self .client .host + endpoint ,
403- json = spec_dict )
410+ json = spec_dict )
404411
405412 self .client .handle_errors (response )
406413
@@ -414,7 +421,7 @@ def generate_export(
414421
415422 def refresh_info (
416423 self ,
417- mode_data = None
424+ mode_data = None
418425 ):
419426 """
420427 Assumptions
@@ -434,7 +441,7 @@ def refresh_info(
434441
435442 response = self .client .session .post (
436443 self .client .host + endpoint ,
437- json = spec_dict )
444+ json = spec_dict )
438445
439446 self .client .handle_errors (response )
440447
@@ -443,4 +450,4 @@ def refresh_info(
443450 # print(data)
444451
445452 self .refresh_from_dict (
446- job_dict = data ['job' ])
453+ job_dict = data ['job' ])
0 commit comments