5454from torchx .util .session import get_session_id_or_create_new , TORCHX_INTERNAL_SESSION_ID
5555
5656from torchx .util .types import none_throws
57- from torchx .workspace .api import WorkspaceMixin
57+ from torchx .workspace .api import Workspace , WorkspaceMixin
5858
5959if TYPE_CHECKING :
6060 from typing_extensions import Self
@@ -171,7 +171,7 @@ def run_component(
171171 component_args : Union [list [str ], dict [str , Any ]],
172172 scheduler : str ,
173173 cfg : Optional [Mapping [str , CfgVal ]] = None ,
174- workspace : Optional [str ] = None ,
174+ workspace : Optional [Union [ Workspace , str ] ] = None ,
175175 parent_run_id : Optional [str ] = None ,
176176 ) -> AppHandle :
177177 """
@@ -206,7 +206,7 @@ def run_component(
206206 ComponentNotFoundException: if the ``component_path`` is failed to resolve.
207207 """
208208
209- with log_event ("run_component" , workspace = workspace ) as ctx :
209+ with log_event ("run_component" ) as ctx :
210210 dryrun_info = self .dryrun_component (
211211 component ,
212212 component_args ,
@@ -217,7 +217,8 @@ def run_component(
217217 )
218218 handle = self .schedule (dryrun_info )
219219 app = none_throws (dryrun_info ._app )
220- ctx ._torchx_event .workspace = workspace
220+
221+ ctx ._torchx_event .workspace = str (workspace )
221222 ctx ._torchx_event .scheduler = none_throws (dryrun_info ._scheduler )
222223 ctx ._torchx_event .app_image = app .roles [0 ].image
223224 ctx ._torchx_event .app_id = parse_app_handle (handle )[2 ]
@@ -230,7 +231,7 @@ def dryrun_component(
230231 component_args : Union [list [str ], dict [str , Any ]],
231232 scheduler : str ,
232233 cfg : Optional [Mapping [str , CfgVal ]] = None ,
233- workspace : Optional [str ] = None ,
234+ workspace : Optional [Union [ Workspace , str ] ] = None ,
234235 parent_run_id : Optional [str ] = None ,
235236 ) -> AppDryRunInfo :
236237 """
@@ -259,7 +260,7 @@ def run(
259260 app : AppDef ,
260261 scheduler : str ,
261262 cfg : Optional [Mapping [str , CfgVal ]] = None ,
262- workspace : Optional [str ] = None ,
263+ workspace : Optional [Union [ Workspace , str ] ] = None ,
263264 parent_run_id : Optional [str ] = None ,
264265 ) -> AppHandle :
265266 """
@@ -272,9 +273,7 @@ def run(
272273 An application handle that is used to call other action APIs on the app.
273274 """
274275
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 :
278277 dryrun_info = self .dryrun (
279278 app ,
280279 scheduler ,
@@ -283,10 +282,15 @@ def run(
283282 parent_run_id = parent_run_id ,
284283 )
285284 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+
290294 return handle
291295
292296 def schedule (self , dryrun_info : AppDryRunInfo ) -> AppHandle :
@@ -320,21 +324,22 @@ def schedule(self, dryrun_info: AppDryRunInfo) -> AppHandle:
320324
321325 """
322326 scheduler = none_throws (dryrun_info ._scheduler )
323- app_image = none_throws (dryrun_info ._app ).roles [0 ].image
324327 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 :
331329 sched = self ._scheduler (scheduler )
332330 app_id = sched .schedule (dryrun_info )
333331 app_handle = make_app_handle (scheduler , self ._name , app_id )
332+
334333 app = none_throws (dryrun_info ._app )
335334 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+
338343 return app_handle
339344
340345 def name (self ) -> str :
@@ -345,7 +350,7 @@ def dryrun(
345350 app : AppDef ,
346351 scheduler : str ,
347352 cfg : Optional [Mapping [str , CfgVal ]] = None ,
348- workspace : Optional [str ] = None ,
353+ workspace : Optional [Union [ Workspace , str ] ] = None ,
349354 parent_run_id : Optional [str ] = None ,
350355 ) -> AppDryRunInfo :
351356 """
@@ -414,7 +419,7 @@ def dryrun(
414419 "dryrun" ,
415420 scheduler ,
416421 runcfg = json .dumps (cfg ) if cfg else None ,
417- workspace = workspace ,
422+ workspace = str ( workspace ) ,
418423 ):
419424 sched = self ._scheduler (scheduler )
420425 resolved_cfg = sched .run_opts ().resolve (cfg )
@@ -429,7 +434,7 @@ def dryrun(
429434 logger .info (
430435 'To disable workspaces pass: --workspace="" from CLI or workspace=None programmatically.'
431436 )
432- sched .build_workspace_and_update_role (role , workspace , resolved_cfg )
437+ sched .build_workspace_and_update_role2 (role , workspace , resolved_cfg )
433438
434439 if old_img != role .image :
435440 logger .info (
0 commit comments