|
9 | 9 |
|
10 | 10 | import asyncio |
11 | 11 | import collections |
| 12 | +import contextlib |
12 | 13 | import datetime |
13 | 14 | import logging |
14 | 15 | from collections import defaultdict |
|
162 | 163 | InvalidEC2TypeInResourcesSpecsError, |
163 | 164 | InvalidKeysInResourcesSpecsError, |
164 | 165 | NodeNotFoundError, |
| 166 | + NodeShareStateCannotBeComputedError, |
165 | 167 | ProjectInvalidRightsError, |
166 | 168 | ProjectLockError, |
167 | 169 | ProjectNodeConnectionsMissingError, |
@@ -1381,10 +1383,10 @@ async def _get_node_share_state( |
1381 | 1383 | status=NodeShareStatus.OPENED, |
1382 | 1384 | ) |
1383 | 1385 | if isinstance(service, NodeGetUnknown): |
1384 | | - # service state is unknown |
1385 | | - # we should raise an exception here |
1386 | | - msg = "Node state is unknown" |
1387 | | - raise RuntimeError(msg) |
| 1386 | + # service state is unknown, raise |
| 1387 | + raise NodeShareStateCannotBeComputedError( |
| 1388 | + project_uuid=project_uuid, node_uuid=node_id |
| 1389 | + ) |
1388 | 1390 | return NodeShareState(locked=False) |
1389 | 1391 |
|
1390 | 1392 | # if the service is computational and no pipeline is running it is not locked |
@@ -1853,19 +1855,23 @@ async def add_project_states_for_user( |
1853 | 1855 | assert isinstance(node_uuid, str) # nosec |
1854 | 1856 | assert isinstance(node, dict) # nosec |
1855 | 1857 |
|
1856 | | - node_lock_state = await _get_node_share_state( |
1857 | | - app, |
1858 | | - user_id=user_id, |
1859 | | - project_uuid=project["uuid"], |
1860 | | - node_id=NodeID(node_uuid), |
1861 | | - ) |
| 1858 | + node_lock_state = None |
| 1859 | + with contextlib.suppress(NodeShareStateCannotBeComputedError): |
| 1860 | + node_lock_state = await _get_node_share_state( |
| 1861 | + app, |
| 1862 | + user_id=user_id, |
| 1863 | + project_uuid=project["uuid"], |
| 1864 | + node_id=NodeID(node_uuid), |
| 1865 | + ) |
1862 | 1866 | if NodeID(node_uuid) in computational_node_states: |
1863 | 1867 | node_state = computational_node_states[NodeID(node_uuid)].model_copy( |
1864 | 1868 | update={"lock_state": node_lock_state} |
1865 | 1869 | ) |
1866 | 1870 | else: |
1867 | 1871 | # if the node is not in the computational state, we create a new one |
1868 | | - service_is_running = node_lock_state.status is NodeShareStatus.OPENED |
| 1872 | + service_is_running = node_lock_state and ( |
| 1873 | + node_lock_state.status is NodeShareStatus.OPENED |
| 1874 | + ) |
1869 | 1875 | node_state = NodeState( |
1870 | 1876 | current_status=( |
1871 | 1877 | RunningState.STARTED |
|
0 commit comments