33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
import logging
|
|
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.credit.exceptions import InsufficientCreditError
|
|
from app.credit.models import CreditTransactionType
|
|
from app.credit.services.credit_service import deduct_credit
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
async def consume_credit(user_uuid: str, session: AsyncSession, *, reason: str = "video generation") -> bool:
|
|
"""크레딧 1 차감. 기존 호출처와 시그니처 호환 유지.
|
|
|
|
.. deprecated::
|
|
사전차감 정책 전환으로 호출처가 사라졌다(video_task.py 의 사후차감 제거).
|
|
**새 코드에서 쓰지 말 것.** 이 함수는 멱등성이 없어 재시도 시 중복 차감된다.
|
|
생성 작업에는 ``credit_service.deduct_credit_for_job`` /
|
|
``refund_credit_for_job`` 을 쓴다.
|
|
다음 릴리스에서 제거 예정.
|
|
"""
|
|
try:
|
|
await deduct_credit(
|
|
session=session,
|
|
user_uuid=user_uuid,
|
|
amount=1,
|
|
type=CreditTransactionType.CONSUME,
|
|
reason=reason,
|
|
)
|
|
return True
|
|
except InsufficientCreditError:
|
|
return False
|