54
54
from torchx .util .session import get_session_id_or_create_new , TORCHX_INTERNAL_SESSION_ID
55
55
56
56
from torchx .util .types import none_throws
57
- from torchx .workspace .api import WorkspaceMixin
57
+ from torchx .workspace .api import Workspace , WorkspaceMixin
58
58
59
59
if TYPE_CHECKING :
60
60
from typing_extensions import Self
@@ -171,7 +171,7 @@ def run_component(
171
171
component_args : Union [list [str ], dict [str , Any ]],
172
172
scheduler : str ,
173
173
cfg : Optional [Mapping [str , CfgVal ]] = None ,
174
- workspace : Optional [str ] = None ,
174
+ workspace : Optional [Union [ Workspace , str ] ] = None ,
175
175
parent_run_id : Optional [str ] = None ,
176
176
) -> AppHandle :
177
177
"""
@@ -206,7 +206,7 @@ def run_component(
206
206
ComponentNotFoundException: if the ``component_path`` is failed to resolve.
207
207
"""
208
208
209
- with log_event ("run_component" , workspace = workspace ) as ctx :
209
+ with log_event ("run_component" ) as ctx :
210
210
dryrun_info = self .dryrun_component (
211
211
component ,
212
212
component_args ,
@@ -217,7 +217,8 @@ def run_component(
217
217
)
218
218
handle = self .schedule (dryrun_info )
219
219
app = none_throws (dryrun_info ._app )
220
- ctx ._torchx_event .workspace = workspace
220
+
221
+ ctx ._torchx_event .workspace = str (workspace )
221
222
ctx ._torchx_event .scheduler = none_throws (dryrun_info ._scheduler )
222
223
ctx ._torchx_event .app_image = app .roles [0 ].image
223
224
ctx ._torchx_event .app_id = parse_app_handle (handle )[2 ]
@@ -230,7 +231,7 @@ def dryrun_component(
230
231
component_args : Union [list [str ], dict [str , Any ]],
231
232
scheduler : str ,
232
233
cfg : Optional [Mapping [str , CfgVal ]] = None ,
233
- workspace : Optional [str ] = None ,
234
+ workspace : Optional [Union [ Workspace , str ] ] = None ,
234
235
parent_run_id : Optional [str ] = None ,
235
236
) -> AppDryRunInfo :
236
237
"""
@@ -259,7 +260,7 @@ def run(
259
260
app : AppDef ,
260
261
scheduler : str ,
261
262
cfg : Optional [Mapping [str , CfgVal ]] = None ,
262
- workspace : Optional [str ] = None ,
263
+ workspace : Optional [Union [ Workspace , str ] ] = None ,
263
264
parent_run_id : Optional [str ] = None ,
264
265
) -> AppHandle :
265
266
"""
@@ -272,9 +273,7 @@ def run(
272
273
An application handle that is used to call other action APIs on the app.
273
274
"""
274
275
275
- with log_event (
276
- api = "run" , runcfg = json .dumps (cfg ) if cfg else None , workspace = workspace
277
- ) as ctx :
276
+ with log_event (api = "run" ) as ctx :
278
277
dryrun_info = self .dryrun (
279
278
app ,
280
279
scheduler ,
@@ -283,10 +282,15 @@ def run(
283
282
parent_run_id = parent_run_id ,
284
283
)
285
284
handle = self .schedule (dryrun_info )
286
- ctx ._torchx_event .scheduler = none_throws (dryrun_info ._scheduler )
287
- ctx ._torchx_event .app_image = none_throws (dryrun_info ._app ).roles [0 ].image
288
- ctx ._torchx_event .app_id = parse_app_handle (handle )[2 ]
289
- ctx ._torchx_event .app_metadata = app .metadata
285
+
286
+ event = ctx ._torchx_event
287
+ event .scheduler = scheduler
288
+ event .runcfg = json .dumps (cfg ) if cfg else None
289
+ event .workspace = str (workspace )
290
+ event .app_id = parse_app_handle (handle )[2 ]
291
+ event .app_image = none_throws (dryrun_info ._app ).roles [0 ].image
292
+ event .app_metadata = app .metadata
293
+
290
294
return handle
291
295
292
296
def schedule (self , dryrun_info : AppDryRunInfo ) -> AppHandle :
@@ -320,21 +324,22 @@ def schedule(self, dryrun_info: AppDryRunInfo) -> AppHandle:
320
324
321
325
"""
322
326
scheduler = none_throws (dryrun_info ._scheduler )
323
- app_image = none_throws (dryrun_info ._app ).roles [0 ].image
324
327
cfg = dryrun_info ._cfg
325
- with log_event (
326
- "schedule" ,
327
- scheduler ,
328
- app_image = app_image ,
329
- runcfg = json .dumps (cfg ) if cfg else None ,
330
- ) as ctx :
328
+ with log_event ("schedule" ) as ctx :
331
329
sched = self ._scheduler (scheduler )
332
330
app_id = sched .schedule (dryrun_info )
333
331
app_handle = make_app_handle (scheduler , self ._name , app_id )
332
+
334
333
app = none_throws (dryrun_info ._app )
335
334
self ._apps [app_handle ] = app
336
- _ , _ , app_id = parse_app_handle (app_handle )
337
- ctx ._torchx_event .app_id = app_id
335
+
336
+ event = ctx ._torchx_event
337
+ event .scheduler = scheduler
338
+ event .runcfg = json .dumps (cfg ) if cfg else None
339
+ event .app_id = app_id
340
+ event .app_image = none_throws (dryrun_info ._app ).roles [0 ].image
341
+ event .app_metadata = app .metadata
342
+
338
343
return app_handle
339
344
340
345
def name (self ) -> str :
@@ -345,7 +350,7 @@ def dryrun(
345
350
app : AppDef ,
346
351
scheduler : str ,
347
352
cfg : Optional [Mapping [str , CfgVal ]] = None ,
348
- workspace : Optional [str ] = None ,
353
+ workspace : Optional [Union [ Workspace , str ] ] = None ,
349
354
parent_run_id : Optional [str ] = None ,
350
355
) -> AppDryRunInfo :
351
356
"""
@@ -414,7 +419,7 @@ def dryrun(
414
419
"dryrun" ,
415
420
scheduler ,
416
421
runcfg = json .dumps (cfg ) if cfg else None ,
417
- workspace = workspace ,
422
+ workspace = str ( workspace ) ,
418
423
):
419
424
sched = self ._scheduler (scheduler )
420
425
resolved_cfg = sched .run_opts ().resolve (cfg )
@@ -429,7 +434,7 @@ def dryrun(
429
434
logger .info (
430
435
'To disable workspaces pass: --workspace="" from CLI or workspace=None programmatically.'
431
436
)
432
- sched .build_workspace_and_update_role (role , workspace , resolved_cfg )
437
+ sched .build_workspace_and_update_role2 (role , workspace , resolved_cfg )
433
438
434
439
if old_img != role .image :
435
440
logger .info (
0 commit comments