add achiv

This commit is contained in:
cheykrym 2026-03-29 01:42:36 +03:00
parent 83b8b932b1
commit 4cd3ea236d
2 changed files with 42 additions and 1 deletions

View File

@ -0,0 +1,41 @@
import asyncio
import httpx
from fastapi import HTTPException, status
from config import settings
from common_lib.utils.http_client import client
async def send_update_increment_to_achievement_service(
user_id: str,
achievement_code: str,
increment: int,
with_httpexception=False,
sleep: int = None
) -> dict:
if sleep:
await asyncio.sleep(sleep)
try:
response = await client.post(
f"{settings.ACHIEVEMENT_SERVICE}/internal/progress-update",
json={
"user_id": str(user_id),
"achievement_code": str(achievement_code),
"increment": int(increment)
})
if response.status_code != 200:
if with_httpexception:
raise HTTPException(
status_code=response.status_code,
detail=f"achievement_service: {response.text}"
)
return response.status_code, f"achievement_service: {response.text}"
wrapped = response.json()
return 200, wrapped
except httpx.RequestError as e:
if with_httpexception:
raise HTTPException(status_code=status.HTTP_503_SERVICE_UNAVAILABLE, detail=f"achievement_service unreachable: {str(e)}")
return 503, f"achievement_service unreachable: {str(e)}"

View File

@ -1,6 +1,6 @@
[project]
name = "common-lib"
version = "0.0.48"
version = "0.0.49"
description = "Библиотека общих компонентов для микросервисов yobble"
authors = [{ name = "cheykrym", email = "you@example.com" }]
license = "MIT"