This commit is contained in:
Yansong Zhang
2025-09-26 11:18:28 +08:00
parent 2b51fc23d9
commit db0780cfa8
2 changed files with 8 additions and 4 deletions

View File

@ -1,3 +1,4 @@
import logging
from typing import Optional
from sqlalchemy import update
@ -7,6 +8,8 @@ from core.errors.error import QuotaExceededError
from extensions.ext_database import db
from models import TenantCreditPool
logger = logging.getLogger(__name__)
class CreditPoolService:
@classmethod
@ -72,8 +75,9 @@ class CreditPoolService:
cls,
tenant_id: str,
credits_required: int,
) -> bool:
):
"""check and deduct credits"""
logger.info("check and deduct credits")
pool = cls.get_pool(tenant_id)
if not pool:
raise QuotaExceededError("Credit pool not found")
@ -93,8 +97,6 @@ class CreditPoolService:
stmt = update(TenantCreditPool).where(*where_conditions).values(**update_values)
db.session.execute(stmt)
return True
@classmethod
def check_deduct_credits(cls, tenant_id: str, credits_required: int) -> bool:
"""check and deduct credits"""