Skip to content

Commit

Permalink
add force release of license seats on stop event
Browse files Browse the repository at this point in the history
  • Loading branch information
matusdrobuliak66 committed Dec 19, 2024
1 parent 8b6b38c commit 42071a0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import sqlalchemy as sa
from models_library.licensed_items import LicensedItemID
from models_library.products import ProductName
from models_library.resource_tracker import ServiceRunId
from models_library.resource_tracker_licensed_items_checkouts import (
LicensedItemCheckoutID,
)
from models_library.rest_ordering import OrderBy, OrderDirection
from models_library.services_types import ServiceRunID
from models_library.wallets import WalletID
from pydantic import NonNegativeInt
from servicelib.rabbitmq.rpc_interfaces.resource_usage_tracker.errors import (
Expand Down Expand Up @@ -225,7 +225,7 @@ async def force_release_license_seats_by_run_id(
engine: AsyncEngine,
connection: AsyncConnection | None = None,
*,
service_run_id: ServiceRunId,
service_run_id: ServiceRunID,
) -> None:
"""
Purpose: This function is utilized by a periodic heartbeat check task that monitors whether running services are
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@
ServiceRunLastHeartbeatUpdate,
ServiceRunStoppedAtUpdate,
)
from .modules.db import credit_transactions_db, pricing_plans_db, service_runs_db
from .modules.db import (
credit_transactions_db,
licensed_items_checkouts_db,
pricing_plans_db,
service_runs_db,
)
from .modules.rabbitmq import RabbitMQClient, get_rabbitmq_client
from .utils import (
compute_service_run_credit_costs,
Expand Down Expand Up @@ -269,9 +274,15 @@ async def _process_stop_event(
running_service = await service_runs_db.update_service_run_stopped_at(
db_engine, data=update_service_run_stopped_at
)
await licensed_items_checkouts_db.force_release_license_seats_by_run_id(
db_engine, service_run_id=msg.service_run_id
)

if running_service is None:
_logger.error("Nothing to update. This should not happen investigate.")
_logger.error(
"Nothing to update. This should not happen investigate. service_run_id: %s",
msg.service_run_id,
)
return

if running_service.wallet_id and running_service.pricing_unit_cost is not None:
Expand Down

0 comments on commit 42071a0

Please sign in to comment.