-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
✨ Introduce wallet exchange 🗃️ #7033
Open
matusdrobuliak66
wants to merge
20
commits into
ITISFoundation:master
Choose a base branch
from
matusdrobuliak66:changing-wallet-after-running-out-of-credits
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,801
−247
Open
Changes from 19 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
8c81f52
daily work
matusdrobuliak66 d3d28fe
Merge branch 'master' into changing-wallet-after-running-out-of-credits
matusdrobuliak66 e18149e
openapi specs
matusdrobuliak66 53a31cb
improbemtns
matusdrobuliak66 bec976b
DB migration
matusdrobuliak66 9487856
fix test
matusdrobuliak66 634c8b9
Merge branch 'master' into changing-wallet-after-running-out-of-credits
matusdrobuliak66 ed94f26
Merge branch 'changing-wallet-after-running-out-of-credits' of github…
matusdrobuliak66 fe27eed
Merge branch 'master' into changing-wallet-after-running-out-of-credits
matusdrobuliak66 d7c6e36
Merge branch 'master' into changing-wallet-after-running-out-of-credits
matusdrobuliak66 32a63e9
improvements and tests
matusdrobuliak66 ec58d66
improvements and tests
matusdrobuliak66 00e6d21
Merge branch 'master' into changing-wallet-after-running-out-of-credits
matusdrobuliak66 c7f6bdb
fix tests
matusdrobuliak66 89bda75
adding unit tests
matusdrobuliak66 de3528a
adding test for open project
matusdrobuliak66 80ccea2
openapi specs
matusdrobuliak66 9b8685f
fix
matusdrobuliak66 61bbbf9
fix
matusdrobuliak66 4bec490
review @sanderegg
matusdrobuliak66 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
64 changes: 64 additions & 0 deletions
64
...-usage-tracker/src/simcore_service_resource_usage_tracker/api/rpc/_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,64 @@ | ||
from fastapi import FastAPI | ||
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.resource_tracker import CreditTransactionStatus | ||
from models_library.wallets import WalletID | ||
from servicelib.rabbitmq import RPCRouter | ||
|
||
from ...services import credit_transactions, service_runs | ||
|
||
router = RPCRouter() | ||
|
||
|
||
@router.expose(reraise_if_error_type=()) | ||
async def get_wallet_total_credits( | ||
app: FastAPI, | ||
*, | ||
product_name: ProductName, | ||
wallet_id: WalletID, | ||
) -> WalletTotalCredits: | ||
return await credit_transactions.sum_wallet_credits( | ||
db_engine=app.state.engine, | ||
product_name=product_name, | ||
wallet_id=wallet_id, | ||
) | ||
|
||
|
||
@router.expose(reraise_if_error_type=()) | ||
async def get_project_wallet_total_credits( | ||
app: FastAPI, | ||
*, | ||
product_name: ProductName, | ||
wallet_id: WalletID, | ||
project_id: ProjectID, | ||
transaction_status: CreditTransactionStatus | None = None, | ||
) -> WalletTotalCredits: | ||
return await service_runs.sum_project_wallet_total_credits( | ||
db_engine=app.state.engine, | ||
product_name=product_name, | ||
wallet_id=wallet_id, | ||
project_id=project_id, | ||
transaction_status=transaction_status, | ||
) | ||
|
||
|
||
@router.expose(reraise_if_error_type=(ValueError,)) | ||
async def pay_project_debt( | ||
app: FastAPI, | ||
*, | ||
project_id: ProjectID, | ||
current_wallet_transaction: CreditTransactionCreateBody, | ||
new_wallet_transaction: CreditTransactionCreateBody, | ||
) -> None: | ||
await credit_transactions.pay_project_debt( | ||
db_engine=app.state.engine, | ||
rabbitmq_client=app.state.rabbitmq_client, | ||
rut_fire_and_forget_tasks=app.state.rut_fire_and_forget_tasks, | ||
project_id=project_id, | ||
current_wallet_transaction=current_wallet_transaction, | ||
new_wallet_transaction=new_wallet_transaction, | ||
) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: this is always in sync with
CreditTransactionStatus
inresource_tracker_credit_transactions.py
? do you test this?Q: same thing with
CreditClassification