24
24
from nbox .hyperloop .jobs .nbox_ws_pb2 import JobRequest
25
25
from nbox .hyperloop .jobs .job_pb2 import Job as JobProto
26
26
from nbox .hyperloop .jobs .dag_pb2 import DAG as DAGProto
27
- from nbox .hyperloop .common .common_pb2 import Resource , Code
27
+ from nbox .hyperloop .common .common_pb2 import Resource
28
28
from nbox .hyperloop .jobs .nbox_ws_pb2 import ListJobsRequest , ListJobsResponse , UpdateJobRequest
29
29
from nbox .hyperloop .deploy .serve_pb2 import ServingListResponse , ServingRequest , Serving , ServingListRequest , ModelRequest , Model as ModelProto , UpdateModelRequest
30
30
@@ -164,7 +164,7 @@ def upload_job_folder(
164
164
method : str ,
165
165
init_folder : str ,
166
166
id : str = "" ,
167
- # name : str = "",
167
+ project_id : str = "" ,
168
168
trigger : bool = False ,
169
169
170
170
# all the things for resources
@@ -206,6 +206,7 @@ def upload_job_folder(
206
206
init_folder (str): folder with all the relevant files or ``file_path:fn_name`` pair so you can use it as the entrypoint.
207
207
name (str, optional): Name of the job. Defaults to "".
208
208
id (str, optional): ID of the job. Defaults to "".
209
+ project_id (str, optional): Project ID, if None uses the one from config. Defaults to "".
209
210
trigger (bool, optional): If uploading a "job" trigger the job after uploading. Defaults to False.
210
211
resource_cpu (str, optional): CPU resource. Defaults to "100m".
211
212
resource_memory (str, optional): Memory resource. Defaults to "128Mi".
@@ -221,6 +222,8 @@ def upload_job_folder(
221
222
from nbox .network import deploy_job , deploy_serving
222
223
import nbox .nbxlib .operator_spec as ospec
223
224
from nbox .nbxlib .serving import SupportedServingTypes as SST
225
+ from nbox .projects import Project
226
+
224
227
OT = ospec .OperatorType
225
228
226
229
if method not in OT ._valid_deployment_types ():
@@ -231,6 +234,17 @@ def upload_job_folder(
231
234
raise ValueError (f"Trigger can only be used with '{ OT .JOB } ' or '{ OT .SERVING } '" )
232
235
if model_name and method != OT .SERVING :
233
236
raise ValueError (f"model_name can only be used with '{ OT .SERVING } '" )
237
+
238
+ # get the correct ID based on the project_id
239
+ if (not project_id and not id ) or (project_id and id ):
240
+ raise ValueError ("Either --project-id or --id must be present" )
241
+ if project_id :
242
+ p = Project (project_id )
243
+ if method == OT .JOB :
244
+ id = p .get_job_id ()
245
+ else :
246
+ id = p .get_deployment_id ()
247
+ logger .info (f"Using project_id: { project_id } , found id: { id } " )
234
248
235
249
if ":" not in init_folder :
236
250
# this means we are uploading a traditonal folder that contains a `nbx_user.py` file
@@ -274,8 +288,8 @@ def upload_job_folder(
274
288
if method == OT .SERVING :
275
289
if serving_type not in SST .all ():
276
290
raise ValueError (f"Invalid serving_type: { serving_type } , should be one of { SST .all ()} " )
277
- if serving_type == SST .FASTAPI :
278
- logger .warning (f"You have selected serving_type='{ SST . FASTAPI } ', this assumes the object: { fn_name } is a FastAPI app" )
291
+ if serving_type == SST .FASTAPI or serving_type == SST . FASTAPI_V2 :
292
+ logger .warning (f"You have selected serving_type='{ serving_type } ', this assumes the object: { fn_name } is a FastAPI app" )
279
293
init_code = fn_name
280
294
perform_tea = False
281
295
load_operator = False
@@ -311,7 +325,8 @@ def upload_job_folder(
311
325
"file_name" : file_name ,
312
326
"fn_name" : fn_name ,
313
327
"init_code" : init_code ,
314
- "load_operator" : load_operator
328
+ "load_operator" : load_operator ,
329
+ "serving_type" : serving_type ,
315
330
}
316
331
317
332
# create a requirements.txt file if it doesn't exist with the latest nbox version
0 commit comments