forked from ITISFoundation/osparc-simcore
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add rpc client for resource usage tracker
- Loading branch information
1 parent
964bb67
commit 97f8d7d
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
services/api-server/src/simcore_service_api_server/services_rpc/resource_usage_tracket.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |