Skip to content

Commit

Permalink
Merge branch 'master' into add-distributed-task-queue
Browse files Browse the repository at this point in the history
  • Loading branch information
giancarloromeo authored Feb 25, 2025
2 parents 2d4951a + 603a27d commit 6d1e32b
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"""add restriction ondelete
Revision ID: d84edab53761
Revises: 163b11424cb1
Create Date: 2025-02-25 09:18:14.541874+00:00
"""
from alembic import op

# revision identifiers, used by Alembic.
revision = "d84edab53761"
down_revision = "163b11424cb1"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_unique_constraint(
"uq_licensed_item_to_resource_resource_id",
"licensed_item_to_resource",
["licensed_resource_id"],
)
op.drop_constraint(
"fk_rut_pricing_plan_to_service_key_and_version",
"resource_tracker_pricing_plan_to_service",
type_="foreignkey",
)
op.create_foreign_key(
"fk_rut_pricing_plan_to_service_key_and_version",
"resource_tracker_pricing_plan_to_service",
"services_meta_data",
["service_key", "service_version"],
["key", "version"],
onupdate="CASCADE",
ondelete="RESTRICT",
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(
"fk_rut_pricing_plan_to_service_key_and_version",
"resource_tracker_pricing_plan_to_service",
type_="foreignkey",
)
op.create_foreign_key(
"fk_rut_pricing_plan_to_service_key_and_version",
"resource_tracker_pricing_plan_to_service",
"services_meta_data",
["service_key", "service_version"],
["key", "version"],
onupdate="CASCADE",
ondelete="CASCADE",
)
op.drop_constraint(
"uq_licensed_item_to_resource_resource_id",
"licensed_item_to_resource",
type_="unique",
)
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,13 @@
),
column_created_datetime(timezone=True),
column_modified_datetime(timezone=True),
#########
# NOTE: Currently, there is a constraint that a resource item ID cannot be in multiple licensed items.
# The reason is that the license key and license version coming from the internal license server are part of the licensed resource domain.
# Sim4Life performs a mapping on their side, where the license key and version are mapped to a licensed item.
# If this constraint is broken, the mapping logic in Sim4Life might break.
sa.UniqueConstraint(
"licensed_resource_id",
name="uq_licensed_item_to_resource_resource_id",
),
)
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@
["services_meta_data.key", "services_meta_data.version"],
name="fk_rut_pricing_plan_to_service_key_and_version",
onupdate=RefActions.CASCADE,
ondelete=RefActions.CASCADE,
ondelete=RefActions.RESTRICT,
),
)
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 6d1e32b

Please sign in to comment.