Skip to content

Commit 91e918f

Browse files
committed
waits until explit projects deleted
1 parent 16ef3d5 commit 91e918f

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

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

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
import asyncio
12
import logging
23

34
from aiohttp import web
45
from servicelib.aiohttp import status
6+
from servicelib.aiohttp.application_keys import APP_FIRE_AND_FORGET_TASKS_KEY
7+
from servicelib.utils import fire_and_forget_task
58

69
from .._meta import API_VTAG as VTAG
710
from ..exception_handling import (
@@ -47,12 +50,23 @@ async def empty_trash(request: web.Request):
4750
user_id = get_user_id(request)
4851
product_name = products_web.get_product_name(request)
4952

50-
# NOTE: This handler waits for all deletions to complete before returning.
51-
# We chose this over hiding the project, as that approach is both costlier to implement
52-
# and duplicates the deletion logic. In the worst case, if deletion is too slow,
53-
# the frontend can disconnect sand retry the request.
54-
await _service.safe_empty_trash(
55-
request.app, product_name=product_name, user_id=user_id
53+
is_fired = asyncio.Event()
54+
55+
fire_and_forget_task(
56+
_service.safe_empty_trash(
57+
request.app,
58+
product_name=product_name,
59+
user_id=user_id,
60+
notify_explicit_projects_deleted=is_fired,
61+
),
62+
task_suffix_name="rest.empty_trash",
63+
fire_and_forget_tasks_collection=request.app[APP_FIRE_AND_FORGET_TASKS_KEY],
5664
)
5765

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

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

Lines changed: 10 additions & 1 deletion
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+
notify_explicit_projects_deleted: asyncio.Event | None = None
104109
):
105110
await _empty_explicitly_trashed_projects(app, product_name, user_id)
106111

112+
# Notify the caller if an event is provided
113+
if notify_explicit_projects_deleted:
114+
notify_explicit_projects_deleted.set()
115+
107116
await _empty_explicitly_trashed_folders_and_content(app, product_name, user_id)
108117

109118

0 commit comments

Comments
 (0)