@@ -1812,41 +1812,35 @@ async def add_project_states_for_user(
18121812 # for templates: the project is never locked and never opened. also the running state is always unknown
18131813 share_state = await _get_project_share_state (user_id , project ["uuid" ], app )
18141814 project_running_state = RunningState .UNKNOWN
1815-
1816- if not is_template and (
1817- computation_task := await director_v2_service .get_computation_task (
1818- app , user_id , project ["uuid" ]
1819- )
1815+ computational_node_states : dict [NodeID , NodeState ] = {}
1816+ if computation_task := await director_v2_service .get_computation_task (
1817+ app , user_id , project ["uuid" ]
18201818 ):
1821- # get the running state
18221819 project_running_state = computation_task .state
1823- # get the nodes individual states
1824- for (
1825- node_id ,
1826- node_state ,
1827- ) in computation_task .pipeline_details .node_states .items ():
1828- prj_node = project ["workbench" ].get (str (node_id ))
1829- if prj_node is None :
1830- continue
1831- node_state_dict = json_loads (
1832- node_state .model_dump_json (by_alias = True , exclude_unset = True )
1833- )
1834- prj_node .setdefault ("state" , {}).update (node_state_dict )
1835- prj_node_progress = node_state_dict .get ("progress" , None ) or 0
1836- prj_node .update ({"progress" : round (prj_node_progress * 100.0 )})
1820+ computational_node_states = computation_task .pipeline_details .node_states
18371821
18381822 for node_uuid , node in project ["workbench" ].items ():
18391823 assert isinstance (node , dict ) # nosec
1824+
18401825 node_lock_state = await _get_node_lock_state (
18411826 app ,
18421827 user_id = user_id ,
18431828 project_uuid = project ["uuid" ],
18441829 node_id = NodeID (node_uuid ),
18451830 )
1846- node .setdefault ("state" , {}).setdefault (
1847- "lock_state" ,
1848- node_lock_state .model_dump (mode = "json" , by_alias = True , exclude_unset = True ),
1831+
1832+ # create complete node state
1833+ node_state = computational_node_states .get (
1834+ NodeID (node_uuid ), NodeState (current_status = RunningState .UNKNOWN )
1835+ )
1836+ node_state .lock_state = node_lock_state
1837+ node_state_dict = json_loads (
1838+ node_state .model_dump_json (by_alias = True , exclude_unset = True )
18491839 )
1840+ node .setdefault ("state" , node_state_dict )
1841+ if "progress" in node ["state" ] and node ["state" ]["progress" ] is not None :
1842+ # ensure progress is a percentage
1843+ node ["progress" ] = round (node ["state" ]["progress" ] * 100.0 )
18501844
18511845 project ["state" ] = ProjectState (
18521846 share_state = share_state , state = ProjectRunningState (value = project_running_state )
0 commit comments