Skip to content

Commit 32ece15

Browse files
committed
waits
1 parent 4a3c8fe commit 32ece15

File tree

1 file changed

+6
-21
lines changed
  • services/web/server/src/simcore_service_webserver/trash

1 file changed

+6
-21
lines changed

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

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

43
from aiohttp import web
54
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
85

96
from .._meta import API_VTAG as VTAG
107
from ..exception_handling import (
@@ -50,24 +47,12 @@ async def empty_trash(request: web.Request):
5047
user_id = get_user_id(request)
5148
product_name = products_web.get_product_name(request)
5249

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-
)
60-
61-
fire_and_forget_task(
62-
_empty_trash(),
63-
task_suffix_name="rest.empty_trash",
64-
fire_and_forget_tasks_collection=request.app[APP_FIRE_AND_FORGET_TASKS_KEY],
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
6556
)
6657

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

0 commit comments

Comments
 (0)