|
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, |
@@ -1382,10 +1384,10 @@ async def _get_node_share_state( |
1382 | 1384 | status=NodeShareStatus.OPENED, |
1383 | 1385 | ) |
1384 | 1386 | if isinstance(service, NodeGetUnknown): |
1385 | | - # service state is unknown |
1386 | | - # we should raise an exception here |
1387 | | - msg = "Node state is unknown" |
1388 | | - raise RuntimeError(msg) |
| 1387 | + # service state is unknown, raise |
| 1388 | + raise NodeShareStateCannotBeComputedError( |
| 1389 | + project_uuid=project_uuid, node_uuid=node_id |
| 1390 | + ) |
1389 | 1391 | return NodeShareState(locked=False) |
1390 | 1392 |
|
1391 | 1393 | # if the service is computational and no pipeline is running it is not locked |
@@ -1879,19 +1881,23 @@ async def add_project_states_for_user( |
1879 | 1881 | assert isinstance(node_uuid, str) # nosec |
1880 | 1882 | assert isinstance(node, dict) # nosec |
1881 | 1883 |
|
1882 | | - node_lock_state = await _get_node_share_state( |
1883 | | - app, |
1884 | | - user_id=user_id, |
1885 | | - project_uuid=project["uuid"], |
1886 | | - node_id=NodeID(node_uuid), |
1887 | | - ) |
| 1884 | + node_lock_state = None |
| 1885 | + with contextlib.suppress(NodeShareStateCannotBeComputedError): |
| 1886 | + node_lock_state = await _get_node_share_state( |
| 1887 | + app, |
| 1888 | + user_id=user_id, |
| 1889 | + project_uuid=project["uuid"], |
| 1890 | + node_id=NodeID(node_uuid), |
| 1891 | + ) |
1888 | 1892 | if NodeID(node_uuid) in computational_node_states: |
1889 | 1893 | node_state = computational_node_states[NodeID(node_uuid)].model_copy( |
1890 | 1894 | update={"lock_state": node_lock_state} |
1891 | 1895 | ) |
1892 | 1896 | else: |
1893 | 1897 | # if the node is not in the computational state, we create a new one |
1894 | | - service_is_running = node_lock_state.status is NodeShareStatus.OPENED |
| 1898 | + service_is_running = node_lock_state and ( |
| 1899 | + node_lock_state.status is NodeShareStatus.OPENED |
| 1900 | + ) |
1895 | 1901 | node_state = NodeState( |
1896 | 1902 | current_status=( |
1897 | 1903 | RunningState.STARTED |
|
0 commit comments