add achiv
This commit is contained in:
parent
83b8b932b1
commit
4cd3ea236d
41
common_lib/services/achievement_service.py
Normal file
41
common_lib/services/achievement_service.py
Normal 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)}"
|
||||
@ -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"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user