Skip to content

Commit 259813e

Browse files
committed
added exception for share state
1 parent 685470b commit 259813e

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,
@@ -1382,10 +1384,10 @@ async def _get_node_share_state(
13821384
status=NodeShareStatus.OPENED,
13831385
)
13841386
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+
)
13891391
return NodeShareState(locked=False)
13901392

13911393
# 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(
18791881
assert isinstance(node_uuid, str) # nosec
18801882
assert isinstance(node, dict) # nosec
18811883

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+
)
18881892
if NodeID(node_uuid) in computational_node_states:
18891893
node_state = computational_node_states[NodeID(node_uuid)].model_copy(
18901894
update={"lock_state": node_lock_state}
18911895
)
18921896
else:
18931897
# 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+
)
18951901
node_state = NodeState(
18961902
current_status=(
18971903
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)