|
1 | | -import asyncio |
2 | 1 | import logging |
3 | 2 |
|
4 | 3 | from aiohttp import web |
5 | 4 | 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 |
8 | 5 |
|
9 | 6 | from .._meta import API_VTAG as VTAG |
10 | 7 | from ..exception_handling import ( |
@@ -50,24 +47,12 @@ async def empty_trash(request: web.Request): |
50 | 47 | user_id = get_user_id(request) |
51 | 48 | product_name = products_web.get_product_name(request) |
52 | 49 |
|
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 |
65 | 56 | ) |
66 | 57 |
|
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 | | - |
73 | 58 | return web.json_response(status=status.HTTP_204_NO_CONTENT) |
0 commit comments