Skip to content

Commit d692486

Browse files
pcrespovmrnicegyu11
authored andcommitted
🎨 web-api: empty_trash operation waits until explicitly trashed projects are deleted (ITISFoundation#7416)
1 parent 2232792 commit d692486

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

‎services/web/server/src/simcore_service_webserver/trash/_rest.py

+10-11
Original file line numberDiff line numberDiff line change
@@ -50,24 +50,23 @@ async def empty_trash(request: web.Request):
5050
user_id = get_user_id(request)
5151
product_name = products_web.get_product_name(request)
5252

53-
is_fired = asyncio.Event()
54-
55-
async def _empty_trash():
56-
is_fired.set()
57-
await _service.safe_empty_trash(
58-
request.app, product_name=product_name, user_id=user_id
59-
)
53+
explicitly_trashed_project_deleted = asyncio.Event()
6054

6155
fire_and_forget_task(
62-
_empty_trash(),
56+
_service.safe_empty_trash(
57+
request.app,
58+
product_name=product_name,
59+
user_id=user_id,
60+
on_explicitly_trashed_projects_deleted=explicitly_trashed_project_deleted,
61+
),
6362
task_suffix_name="rest.empty_trash",
6463
fire_and_forget_tasks_collection=request.app[APP_FIRE_AND_FORGET_TASKS_KEY],
6564
)
6665

67-
# NOTE: Ensures `fire_and_forget_task` is triggered; otherwise,
68-
# when the front-end requests the trash item list,
66+
# NOTE: Ensures `fire_and_forget_task` is triggered and deletes explicit projects;
67+
# otherwise, when the front-end requests the trash item list,
6968
# it may still display items, misleading the user into
7069
# thinking the `empty trash` operation failed.
71-
await is_fired.wait()
70+
await explicitly_trashed_project_deleted.wait()
7271

7372
return web.json_response(status=status.HTTP_204_NO_CONTENT)

‎services/web/server/src/simcore_service_webserver/trash/_service.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import asyncio
12
import logging
23
from datetime import timedelta
34
from typing import Final
@@ -100,10 +101,18 @@ async def _empty_explicitly_trashed_folders_and_content(
100101

101102

102103
async def safe_empty_trash(
103-
app: web.Application, *, product_name: ProductName, user_id: UserID
104+
app: web.Application,
105+
*,
106+
product_name: ProductName,
107+
user_id: UserID,
108+
on_explicitly_trashed_projects_deleted: asyncio.Event | None = None
104109
):
110+
# Delete explicitly trashed projects & notify
105111
await _empty_explicitly_trashed_projects(app, product_name, user_id)
112+
if on_explicitly_trashed_projects_deleted:
113+
on_explicitly_trashed_projects_deleted.set()
106114

115+
# Delete explicitly trashed folders (and all implicitly trashed sub-folders and projects)
107116
await _empty_explicitly_trashed_folders_and_content(app, product_name, user_id)
108117

109118

0 commit comments

Comments
 (0)