mirror of
https://github.com/langgenius/dify.git
synced 2026-03-10 19:21:50 +08:00
add:log
This commit is contained in:
parent
2b51fc23d9
commit
db0780cfa8
@ -133,9 +133,10 @@ def handle(sender: Message, **kwargs):
|
|||||||
system_configuration=system_configuration,
|
system_configuration=system_configuration,
|
||||||
model_name=model_config.model,
|
model_name=model_config.model,
|
||||||
)
|
)
|
||||||
|
logger.info("used_quota: %s", used_quota)
|
||||||
if used_quota is not None:
|
if used_quota is not None:
|
||||||
if provider_configuration.system_configuration.current_quota_type == ProviderQuotaType.TRIAL:
|
if provider_configuration.system_configuration.current_quota_type == ProviderQuotaType.TRIAL:
|
||||||
|
logger.info("deduct credits")
|
||||||
from services.credit_pool_service import CreditPoolService
|
from services.credit_pool_service import CreditPoolService
|
||||||
|
|
||||||
CreditPoolService.check_and_deduct_credits(
|
CreditPoolService.check_and_deduct_credits(
|
||||||
@ -143,6 +144,7 @@ def handle(sender: Message, **kwargs):
|
|||||||
credits_required=used_quota,
|
credits_required=used_quota,
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
|
logger.info("update provider quota")
|
||||||
quota_update = _ProviderUpdateOperation(
|
quota_update = _ProviderUpdateOperation(
|
||||||
filters=_ProviderUpdateFilters(
|
filters=_ProviderUpdateFilters(
|
||||||
tenant_id=tenant_id,
|
tenant_id=tenant_id,
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import logging
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from sqlalchemy import update
|
from sqlalchemy import update
|
||||||
@ -7,6 +8,8 @@ from core.errors.error import QuotaExceededError
|
|||||||
from extensions.ext_database import db
|
from extensions.ext_database import db
|
||||||
from models import TenantCreditPool
|
from models import TenantCreditPool
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class CreditPoolService:
|
class CreditPoolService:
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -72,8 +75,9 @@ class CreditPoolService:
|
|||||||
cls,
|
cls,
|
||||||
tenant_id: str,
|
tenant_id: str,
|
||||||
credits_required: int,
|
credits_required: int,
|
||||||
) -> bool:
|
):
|
||||||
"""check and deduct credits"""
|
"""check and deduct credits"""
|
||||||
|
logger.info("check and deduct credits")
|
||||||
pool = cls.get_pool(tenant_id)
|
pool = cls.get_pool(tenant_id)
|
||||||
if not pool:
|
if not pool:
|
||||||
raise QuotaExceededError("Credit pool not found")
|
raise QuotaExceededError("Credit pool not found")
|
||||||
@ -93,8 +97,6 @@ class CreditPoolService:
|
|||||||
stmt = update(TenantCreditPool).where(*where_conditions).values(**update_values)
|
stmt = update(TenantCreditPool).where(*where_conditions).values(**update_values)
|
||||||
db.session.execute(stmt)
|
db.session.execute(stmt)
|
||||||
|
|
||||||
return True
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def check_deduct_credits(cls, tenant_id: str, credits_required: int) -> bool:
|
def check_deduct_credits(cls, tenant_id: str, credits_required: int) -> bool:
|
||||||
"""check and deduct credits"""
|
"""check and deduct credits"""
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user