22
33
44class Job ():
5-
5+ valid_output_dir_actions = [ 'copy' , 'move' ]
66 def __init__ (self ,
77 client ,
88 job_dict = None ):
@@ -137,6 +137,31 @@ def serialize(self):
137137 'member_list_ids' : self .member_list_ids ,
138138 'tag_list' : self .tag_list
139139 }
140+ def attach_output_dir (self , dir : Directory , action = 'copy' ):
141+
142+ if action not in self .valid_output_dir_actions :
143+ raise ValueError (f'Invalid actions. Can only be { self .valid_output_dir_actions } ' )
144+
145+ data = {
146+ 'job_id' : self .id ,
147+ 'output_dir' : str (dir .id ),
148+ 'output_dir_action' : action
149+ }
150+ endpoint = "/api/v1/project/{}/job/set-output-dir" .format (self .client .project_string_id )
151+ response = self .client .session .post (
152+ self .client .host + endpoint ,
153+ json = data )
154+
155+ self .client .handle_errors (response )
156+
157+ data = response .json ()
158+
159+ if data ["log" ]["success" ] == True :
160+ # TODO review better way to update fields
161+ self .id = data ["job" ]["id" ]
162+
163+ return self
164+
140165
141166 def new (self ,
142167 name = None ,
@@ -157,6 +182,8 @@ def new(self,
157182 members_list_ids = [],
158183 auto_launch = True ,
159184 tag_list = [],
185+ output_dir = None ,
186+ output_dir_action = None
160187 ):
161188 """
162189
@@ -227,6 +254,10 @@ def new(self,
227254 if guide :
228255 job .guide_update (guide = guide )
229256
257+ if output_dir and output_dir_action :
258+ if output_dir_action not in self .valid_output_dir_actions :
259+ raise ValueError (f'Invalid actions. Can only be { self .valid_output_dir_actions } ' )
260+ job .attach_output_dir (dir = output_dir , action = output_dir_action )
230261 if auto_launch :
231262 endpoint_launch = "/api/v1/job/launch" .format (self .client .project_string_id )
232263 response = self .client .session .post (
0 commit comments