-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into enh/e2e-ids
- Loading branch information
Showing
37 changed files
with
1,830 additions
and
248 deletions.
There are no files selected for viewing
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
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
35 changes: 35 additions & 0 deletions
35
...stgres_database/migration/versions/a3a58471b0f1_add_credit_transaction_classification_.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,35 @@ | ||
"""add credit transaction classification enums | ||
Revision ID: a3a58471b0f1 | ||
Revises: f19905923355 | ||
Create Date: 2025-01-14 13:44:05.025647+00:00 | ||
""" | ||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "a3a58471b0f1" | ||
down_revision = "f19905923355" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
op.execute(sa.DDL("ALTER TYPE credittransactionstatus ADD VALUE 'IN_DEBT'")) | ||
op.execute( | ||
sa.DDL( | ||
"ALTER TYPE credittransactionclassification ADD VALUE 'ADD_WALLET_EXCHANGE'" | ||
) | ||
) | ||
op.execute( | ||
sa.DDL( | ||
"ALTER TYPE credittransactionclassification ADD VALUE 'DEDUCT_WALLET_EXCHANGE'" | ||
) | ||
) | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
pass | ||
# ### end Alembic commands ### |
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
84 changes: 84 additions & 0 deletions
84
...rary/src/servicelib/rabbitmq/rpc_interfaces/resource_usage_tracker/credit_transactions.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,84 @@ | ||
import logging | ||
from typing import Final | ||
|
||
from models_library.api_schemas_resource_usage_tracker import ( | ||
RESOURCE_USAGE_TRACKER_RPC_NAMESPACE, | ||
) | ||
from models_library.api_schemas_resource_usage_tracker.credit_transactions import ( | ||
CreditTransactionCreateBody, | ||
WalletTotalCredits, | ||
) | ||
from models_library.products import ProductName | ||
from models_library.projects import ProjectID | ||
from models_library.rabbitmq_basic_types import RPCMethodName | ||
from models_library.resource_tracker import CreditTransactionStatus | ||
from models_library.wallets import WalletID | ||
from pydantic import NonNegativeInt, TypeAdapter | ||
|
||
from ....logging_utils import log_decorator | ||
from ....rabbitmq import RabbitMQRPCClient | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
_DEFAULT_TIMEOUT_S: Final[NonNegativeInt] = 20 | ||
|
||
_RPC_METHOD_NAME_ADAPTER: TypeAdapter[RPCMethodName] = TypeAdapter(RPCMethodName) | ||
|
||
|
||
@log_decorator(_logger, level=logging.DEBUG) | ||
async def get_wallet_total_credits( | ||
rabbitmq_rpc_client: RabbitMQRPCClient, | ||
*, | ||
product_name: ProductName, | ||
wallet_id: WalletID, | ||
) -> WalletTotalCredits: | ||
result = await rabbitmq_rpc_client.request( | ||
RESOURCE_USAGE_TRACKER_RPC_NAMESPACE, | ||
_RPC_METHOD_NAME_ADAPTER.validate_python("get_wallet_total_credits"), | ||
product_name=product_name, | ||
wallet_id=wallet_id, | ||
timeout_s=_DEFAULT_TIMEOUT_S, | ||
) | ||
assert isinstance(result, WalletTotalCredits) # nosec | ||
return result | ||
|
||
|
||
@log_decorator(_logger, level=logging.DEBUG) | ||
async def get_project_wallet_total_credits( | ||
rabbitmq_rpc_client: RabbitMQRPCClient, | ||
*, | ||
product_name: ProductName, | ||
wallet_id: WalletID, | ||
project_id: ProjectID, | ||
transaction_status: CreditTransactionStatus | None = None, | ||
) -> WalletTotalCredits: | ||
result = await rabbitmq_rpc_client.request( | ||
RESOURCE_USAGE_TRACKER_RPC_NAMESPACE, | ||
_RPC_METHOD_NAME_ADAPTER.validate_python("get_project_wallet_total_credits"), | ||
product_name=product_name, | ||
wallet_id=wallet_id, | ||
project_id=project_id, | ||
transaction_status=transaction_status, | ||
timeout_s=_DEFAULT_TIMEOUT_S, | ||
) | ||
assert isinstance(result, WalletTotalCredits) # nosec | ||
return result | ||
|
||
|
||
@log_decorator(_logger, level=logging.DEBUG) | ||
async def pay_project_debt( | ||
rabbitmq_rpc_client: RabbitMQRPCClient, | ||
*, | ||
project_id: ProjectID, | ||
current_wallet_transaction: CreditTransactionCreateBody, | ||
new_wallet_transaction: CreditTransactionCreateBody, | ||
) -> None: | ||
await rabbitmq_rpc_client.request( | ||
RESOURCE_USAGE_TRACKER_RPC_NAMESPACE, | ||
_RPC_METHOD_NAME_ADAPTER.validate_python("pay_project_debt"), | ||
project_id=project_id, | ||
current_wallet_transaction=current_wallet_transaction, | ||
new_wallet_transaction=new_wallet_transaction, | ||
timeout_s=_DEFAULT_TIMEOUT_S, | ||
) |
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
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
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
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
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
Oops, something went wrong.