Skip to content

Commit 276f866

Browse files
committed
added exception for share state
1 parent 6bfd06b commit 276f866

File tree

2 files changed

+32
-12
lines changed

2 files changed

+32
-12
lines changed

services/web/server/src/simcore_service_webserver/projects/_projects_service.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import asyncio
1111
import collections
12+
import contextlib
1213
import datetime
1314
import logging
1415
from collections import defaultdict
@@ -162,6 +163,7 @@
162163
InvalidEC2TypeInResourcesSpecsError,
163164
InvalidKeysInResourcesSpecsError,
164165
NodeNotFoundError,
166+
NodeShareStateCannotBeComputedError,
165167
ProjectInvalidRightsError,
166168
ProjectLockError,
167169
ProjectNodeConnectionsMissingError,
@@ -1381,10 +1383,10 @@ async def _get_node_share_state(
13811383
status=NodeShareStatus.OPENED,
13821384
)
13831385
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+
)
13881390
return NodeShareState(locked=False)
13891391

13901392
# 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(
18531855
assert isinstance(node_uuid, str) # nosec
18541856
assert isinstance(node, dict) # nosec
18551857

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+
)
18621866
if NodeID(node_uuid) in computational_node_states:
18631867
node_state = computational_node_states[NodeID(node_uuid)].model_copy(
18641868
update={"lock_state": node_lock_state}
18651869
)
18661870
else:
18671871
# 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+
)
18691875
node_state = NodeState(
18701876
current_status=(
18711877
RunningState.STARTED

services/web/server/src/simcore_service_webserver/projects/exceptions.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from typing import Any
55

66
from models_library.projects import ProjectID
7+
from models_library.projects_nodes_io import NodeID
78
from models_library.users import UserID
89
from servicelib.redis import ProjectLockError
910

@@ -106,7 +107,9 @@ class ProjectRunningConflictError(ProjectTrashError):
106107

107108

108109
class ProjectNotTrashedError(ProjectTrashError):
109-
msg_template = "Cannot delete project {project_uuid} since it was not trashed first: {details}"
110+
msg_template = (
111+
"Cannot delete project {project_uuid} since it was not trashed first: {details}"
112+
)
110113

111114

112115
class NodeNotFoundError(BaseProjectError):
@@ -118,6 +121,17 @@ def __init__(self, *, project_uuid: str, node_uuid: str, **ctx):
118121
self.project_uuid = project_uuid
119122

120123

124+
class NodeShareStateCannotBeComputedError(BaseProjectError):
125+
msg_template = (
126+
"Node '{node_uuid}' share state cannot be computed in project '{project_uuid}'"
127+
)
128+
129+
def __init__(self, *, project_uuid: ProjectID | None, node_uuid: NodeID, **ctx):
130+
super().__init__(**ctx)
131+
self.node_uuid = node_uuid
132+
self.project_uuid = project_uuid
133+
134+
121135
class ParentNodeNotFoundError(BaseProjectError):
122136
msg_template = "Parent node '{node_uuid}' not found"
123137

0 commit comments

Comments
 (0)