Skip to content

🎨 web-api: empty_trash operation waits until explicitly trashed projects are deleted #7416

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions services/web/server/src/simcore_service_webserver/trash/_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,23 @@ async def empty_trash(request: web.Request):
user_id = get_user_id(request)
product_name = products_web.get_product_name(request)

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
)
explicitly_trashed_project_deleted = asyncio.Event()

fire_and_forget_task(
_empty_trash(),
_service.safe_empty_trash(
request.app,
product_name=product_name,
user_id=user_id,
on_explicitly_trashed_projects_deleted=explicitly_trashed_project_deleted,
),
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,
# NOTE: Ensures `fire_and_forget_task` is triggered and deletes explicit projects;
# 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()
await explicitly_trashed_project_deleted.wait()

return web.json_response(status=status.HTTP_204_NO_CONTENT)
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
import logging
from datetime import timedelta
from typing import Final
Expand Down Expand Up @@ -100,10 +101,18 @@ async def _empty_explicitly_trashed_folders_and_content(


async def safe_empty_trash(
app: web.Application, *, product_name: ProductName, user_id: UserID
app: web.Application,
*,
product_name: ProductName,
user_id: UserID,
on_explicitly_trashed_projects_deleted: asyncio.Event | None = None
):
# Delete explicitly trashed projects & notify
await _empty_explicitly_trashed_projects(app, product_name, user_id)
if on_explicitly_trashed_projects_deleted:
on_explicitly_trashed_projects_deleted.set()

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


Expand Down
Loading