2
2
3
3
4
4
class Job ():
5
-
5
+ valid_output_dir_actions = [ 'copy' , 'move' ]
6
6
def __init__ (self ,
7
7
client ,
8
8
job_dict = None ):
@@ -137,6 +137,31 @@ def serialize(self):
137
137
'member_list_ids' : self .member_list_ids ,
138
138
'tag_list' : self .tag_list
139
139
}
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
+
140
165
141
166
def new (self ,
142
167
name = None ,
@@ -157,6 +182,8 @@ def new(self,
157
182
members_list_ids = [],
158
183
auto_launch = True ,
159
184
tag_list = [],
185
+ output_dir = None ,
186
+ output_dir_action = None
160
187
):
161
188
"""
162
189
@@ -227,6 +254,10 @@ def new(self,
227
254
if guide :
228
255
job .guide_update (guide = guide )
229
256
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 )
230
261
if auto_launch :
231
262
endpoint_launch = "/api/v1/job/launch" .format (self .client .project_string_id )
232
263
response = self .client .session .post (
0 commit comments