Lowered returned messages because Windows only displays a limited amount of notifications
This commit is contained in:
1 parent
79ba5e1887
commit
588ce719d3
1 file changed
+2
-11
+2
-11
@@ -21,7 +21,6 @@ from validator import verify_api_key
|
||||
|
||||
logger = setup_logger(__name__)
|
||||
api_key_header_internal = APIKeyHeader(name="X-API-Key-Internal")
|
||||
MAX_PAGES = 5
|
||||
|
||||
class Notification(BaseModel):
|
||||
user_id : int = Field(gt=0) #ToDo fix among all services
|
||||
@@ -155,26 +154,18 @@ async def pull_notifications(
|
||||
logger.debug(f"[FastAPI] User id {user_id} is requesting messages")
|
||||
client: httpx.AsyncClient = request.app.state.http_client
|
||||
|
||||
messages: list[dict] = []
|
||||
has_more = False
|
||||
|
||||
try:
|
||||
for _ in range(MAX_PAGES):
|
||||
resp = await client.post("/internal/pull-notifications", json={"user_id": user_id})
|
||||
resp.raise_for_status()
|
||||
data = PullResponse.model_validate(resp.json())
|
||||
|
||||
messages.extend(data.messages)
|
||||
has_more = data.has_more
|
||||
if not has_more:
|
||||
break
|
||||
except (httpx.HTTPError, ValueError) as e:
|
||||
logger.error(f"[FastAPI] Pull service failed for user_id={user_id}: {e!r}")
|
||||
status = 504 if isinstance(e, httpx.TimeoutException) else 502
|
||||
raise HTTPException(status_code=status, detail="Notification service unavailable") from e
|
||||
|
||||
logger.info(f"[FastAPI] Returning {len(messages)} message(s) for user_id={user_id}, has_more={has_more}")
|
||||
return PullResponse(messages=messages, count=len(messages), has_more=has_more)
|
||||
logger.info(f"[FastAPI] Returning {len(data.messages)} message(s) for user_id={user_id}, has_more={data.has_more}")
|
||||
return data
|
||||
|
||||
async def start_servers():
|
||||
logger.debug("Starting FastAPI and metrics servers")
|
||||
|
||||
Reference in new issue
Block a user