Skip to content

Commit

Permalink
add rpc client for resource usage tracker
Browse files Browse the repository at this point in the history
  • Loading branch information
bisgaard-itis committed Jan 7, 2025
1 parent 964bb67 commit 97f8d7d
Showing 1 changed file with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from dataclasses import dataclass
from functools import partial

from fastapi import FastAPI
from models_library.resource_tracker_licensed_items_checkouts import (
LicensedItemCheckoutID,
)
from servicelib.rabbitmq._client_rpc import RabbitMQRPCClient
from servicelib.rabbitmq.rpc_interfaces.resource_usage_tracker.licensed_items_checkouts import (
get_licensed_item_checkout as _get_licensed_item_checkout,
)

from ..exceptions.service_errors_utils import service_exception_mapper
from ..models.schemas.model_adapter import LicensedItemCheckoutGet

_exception_mapper = partial(
service_exception_mapper, service_name="ResourceUsageTracker"
)


@dataclass
class ResourceUsageTrackerClient:
_client: RabbitMQRPCClient

@_exception_mapper(rpc_exception_map={})
async def get_licensed_item_checkout(
self, *, product_name: str, licensed_item_checkout_id: LicensedItemCheckoutID
) -> LicensedItemCheckoutGet:
_licensed_item_checkout = await _get_licensed_item_checkout(
rabbitmq_rpc_client=self._client,
product_name=product_name,
licensed_item_checkout_id=licensed_item_checkout_id,
)
return LicensedItemCheckoutGet(
licensed_item_checkout_id=_licensed_item_checkout.licensed_item_checkout_id,
licensed_item_id=_licensed_item_checkout.licensed_item_id,
wallet_id=_licensed_item_checkout.wallet_id,
user_id=_licensed_item_checkout.user_id,
product_name=_licensed_item_checkout.product_name,
started_at=_licensed_item_checkout.started_at,
stopped_at=_licensed_item_checkout.stopped_at,
num_of_seats=_licensed_item_checkout.num_of_seats,
)


def setup(app: FastAPI, rabbitmq_rmp_client: RabbitMQRPCClient):
app.state.wb_api_rpc_client = ResourceUsageTrackerClient(
_client=rabbitmq_rmp_client
)

0 comments on commit 97f8d7d

Please sign in to comment.