Skip to content

Commit 5fe4d98

Browse files
fix lost of logs
1 parent 1efd09c commit 5fe4d98

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

services/web/server/src/simcore_service_webserver/projects/_controller/projects_states_rest.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
from ...notifications import project_logs
2929
from ...products import products_web
3030
from ...products.models import Product
31-
from ...resource_manager.user_sessions import managed_resource
31+
from ...resource_manager.user_sessions import PROJECT_ID_KEY, managed_resource
3232
from ...security.decorators import permission_required
3333
from ...socketio.server import get_socket_server
3434
from ...users import users_service
@@ -91,11 +91,17 @@ async def open_project(request: web.Request) -> web.Response:
9191
),
9292
)
9393

94+
# Check if projects wallet is not in debt
9495
await projects_wallets_service.check_project_financial_status(
9596
request.app,
9697
project_id=path_params.project_id,
9798
product_name=req_ctx.product_name,
9899
)
100+
# Check if user has access to a project wallet (Useful for simultaneous access to project by different users)
101+
project_wallet = await projects_wallets_service.get_project_wallet(
102+
request.app,
103+
project_id=path_params.project_id,
104+
)
99105

100106
product: Product = products_web.get_current_product(request)
101107
app_settings = get_application_settings(request.app)
@@ -220,7 +226,17 @@ async def close_project(request: web.Request) -> web.Response:
220226
X_SIMCORE_USER_AGENT, UNDEFINED_DEFAULT_SIMCORE_USER_AGENT_VALUE
221227
),
222228
)
223-
await project_logs.unsubscribe(request.app, path_params.project_id)
229+
230+
with managed_resource(
231+
req_ctx.user_id, client_session_id, request.app
232+
) as user_session:
233+
all_user_sessions_with_project = await user_session.find_users_of_resource(
234+
request.app, key=PROJECT_ID_KEY, value=f"{path_params.project_id}"
235+
)
236+
# Only unsubscribe from logs if there is no other occurrence of the open project
237+
if len(all_user_sessions_with_project) == 0:
238+
await project_logs.unsubscribe(request.app, path_params.project_id)
239+
224240
return web.json_response(status=status.HTTP_204_NO_CONTENT)
225241

226242

services/web/server/src/simcore_service_webserver/resource_manager/user_sessions.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from collections.abc import Iterator
33
from contextlib import contextmanager
44
from dataclasses import dataclass
5-
from functools import cached_property
65
from typing import Final
76

87
from aiohttp import web
@@ -64,7 +63,7 @@ class UserSessionResourcesRegistry:
6463
def _registry(self) -> RedisResourceRegistry:
6564
return get_registry(self.app)
6665

67-
@cached_property
66+
@property
6867
def resource_key(self) -> UserSession:
6968
return UserSession(
7069
user_id=self.user_id,
@@ -148,8 +147,11 @@ async def find_all_resources_of_user(self, key: str) -> list[str]:
148147
msg=f"{self.user_id=} finding all {key} from registry",
149148
extra=get_log_record_extra(user_id=self.user_id),
150149
):
151-
return await get_registry(self.app).find_resources(
152-
UserSession(user_id=self.user_id, client_session_id="*"), key
150+
return await self._registry.find_resources(
151+
UserSession(
152+
user_id=self.user_id, client_session_id="*"
153+
), # <-- this one checks for all user tabs
154+
key,
153155
)
154156

155157
async def find(self, resource_name: str) -> list[str]:
@@ -161,7 +163,10 @@ async def find(self, resource_name: str) -> list[str]:
161163
extra=get_log_record_extra(user_id=self.user_id),
162164
)
163165

164-
return await self._registry.find_resources(self.resource_key, resource_name)
166+
return await self._registry.find_resources(
167+
self.resource_key,
168+
resource_name, # <-- when initialized with specific tab (client_session_id), checks only that tab otherwise all tabs
169+
)
165170

166171
async def add(self, key: str, value: str) -> None:
167172
_logger.debug(

0 commit comments

Comments
 (0)