Skip to content

Commit

Permalink
🎨 Improves empty-trash to avoid misleading the user (#7267)
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov authored Feb 25, 2025
1 parent e3fdf00 commit e7e0b79
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions services/web/server/src/simcore_service_webserver/trash/_rest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
import logging

from aiohttp import web
Expand All @@ -20,10 +21,6 @@

_logger = logging.getLogger(__name__)

#
# EXCEPTIONS HANDLING
#


_TO_HTTP_ERROR_MAP: ExceptionToHttpErrorMap = {
ProjectRunningConflictError: HttpErrorInfo(
Expand All @@ -42,10 +39,6 @@
)


#
# ROUTES
#

routes = web.RouteTableDef()


Expand All @@ -57,12 +50,24 @@ async def empty_trash(request: web.Request):
user_id = get_user_id(request)
product_name = get_product_name(request)

fire_and_forget_task(
_service.safe_empty_trash(
is_fired = asyncio.Event()

async def _empty_trash():
is_fired.set()
await _service.safe_empty_trash(
request.app, product_name=product_name, user_id=user_id
),
)

fire_and_forget_task(
_empty_trash(),
task_suffix_name="rest.empty_trash",
fire_and_forget_tasks_collection=request.app[APP_FIRE_AND_FORGET_TASKS_KEY],
)

# NOTE: Ensures `fire_and_forget_task` is triggered; otherwise,
# when the front-end requests the trash item list,
# it may still display items, misleading the user into
# thinking the `empty trash` operation failed.
await is_fired.wait()

return web.json_response(status=status.HTTP_204_NO_CONTENT)

0 comments on commit e7e0b79

Please sign in to comment.