Код: Выделить всё
@router.post("/")
async def process_one(current_user = Depends(get_current_user),
db_session: Session = Depends(get_db_session)):
try:
if current_user.credits < 10:
raise HTTPException(status_code=400, detail="Insufficient credits")
current_user.credits -= 10
db_session.flush()
time.sleep(300) # some processing that will take 2-3 minutes
db_session.commit() # no error so commit to database
return {"status", "success"}
except Exception as e:
raise HTTPException(status_code=500, detail="Internal Server Error")
ChatGPT предложил заблокировать запись пользователя, но я не думаю, что это правильное решение, поскольку пользователь не сможет позвони в любой другой API (поскольку все API будут вычитать кредиты пользователей, чтобы они могли делать обновления, но запись заблокирована).
Подробнее здесь: https://stackoverflow.com/questions/785 ... on-fastapi
Мобильная версия