Skip to content

Commit 6780bde

Browse files
committed
re-use same code to close project
1 parent 7b19827 commit 6780bde

File tree

1 file changed

+32
-49
lines changed

1 file changed

+32
-49
lines changed

services/web/server/src/simcore_service_webserver/garbage_collector/_core_disconnected.py

Lines changed: 32 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -73,57 +73,40 @@ async def remove_disconnected_user_resources(
7373
dead_session,
7474
]
7575

76-
# Every resource might be SHARED with other keys.
77-
# In that case, the resource is released by THE LAST DYING KEY
78-
# (we could call this the "last-standing-man" pattern! :-) )
79-
#
80-
other_sessions_with_this_resource = [
81-
k
82-
for k in await registry.find_keys((resource_name, f"{resource_value}"))
83-
if k != dead_session
84-
]
85-
is_resource_still_in_use: bool = any(
86-
k in all_session_alive for k in other_sessions_with_this_resource
76+
# (1) releasing acquired resources
77+
_logger.info(
78+
"(1) Releasing resource %s:%s acquired by expired %s",
79+
f"{resource_name=}",
80+
f"{resource_value=}",
81+
f"{dead_session!r}",
8782
)
8883

89-
if not is_resource_still_in_use:
90-
# adds the remaining resource entries for (2)
91-
keys_to_update.extend(other_sessions_with_this_resource)
92-
93-
# (1) releasing acquired resources
94-
_logger.info(
95-
"(1) Releasing resource %s:%s acquired by expired %s",
96-
f"{resource_name=}",
97-
f"{resource_value=}",
98-
f"{dead_session!r}",
99-
)
100-
101-
if resource_name == "project_id":
102-
# inform that the project can be closed on the backend side
103-
#
104-
try:
105-
_logger.info(
106-
"Closing project '%s' of user %s", resource_value, user_id
107-
)
108-
await _projects_service.try_close_project_for_user(
109-
user_id,
110-
f"{resource_value}",
111-
dead_session["client_session_id"],
112-
app,
113-
simcore_user_agent=UNDEFINED_DEFAULT_SIMCORE_USER_AGENT_VALUE,
114-
wait_for_service_closed=True,
115-
)
116-
117-
except (ProjectNotFoundError, ProjectLockError) as err:
118-
_logger.warning(
119-
(
120-
"Could not remove project interactive services user_id=%s "
121-
"project_uuid=%s. Check the logs above for details [%s]"
122-
),
123-
user_id,
124-
resource_value,
125-
err,
126-
)
84+
if resource_name == "project_id":
85+
# inform that the project can be closed on the backend side
86+
#
87+
try:
88+
_logger.info(
89+
"Closing project '%s' of user %s", resource_value, user_id
90+
)
91+
await _projects_service.try_close_project_for_user(
92+
user_id,
93+
f"{resource_value}",
94+
dead_session["client_session_id"],
95+
app,
96+
simcore_user_agent=UNDEFINED_DEFAULT_SIMCORE_USER_AGENT_VALUE,
97+
wait_for_service_closed=True,
98+
)
99+
100+
except (ProjectNotFoundError, ProjectLockError) as err:
101+
_logger.warning(
102+
(
103+
"Could not remove project interactive services user_id=%s "
104+
"project_uuid=%s. Check the logs above for details [%s]"
105+
),
106+
user_id,
107+
resource_value,
108+
err,
109+
)
127110

128111
# ONLY GUESTS: if this user was a GUEST also remove it from the database
129112
# with the only associated project owned

0 commit comments

Comments
 (0)