Lowered returned messages because Windows only displays a limited amount of notifications

This commit is contained in:
florian committed 2026-10-14 16:15:13 +02:00
1 parent 79ba5e1887
commit 588ce719d3
1 file changed
+5 -14
+5 -14
View File
@@ -21,7 +21,6 @@ from validator import verify_api_key
logger = setup_logger(__name__) logger = setup_logger(__name__)
api_key_header_internal = APIKeyHeader(name="X-API-Key-Internal") api_key_header_internal = APIKeyHeader(name="X-API-Key-Internal")
MAX_PAGES = 5
class Notification(BaseModel): class Notification(BaseModel):
user_id : int = Field(gt=0) #ToDo fix among all services 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") logger.debug(f"[FastAPI] User id {user_id} is requesting messages")
client: httpx.AsyncClient = request.app.state.http_client client: httpx.AsyncClient = request.app.state.http_client
messages: list[dict] = []
has_more = False
try: try:
for _ in range(MAX_PAGES): resp = await client.post("/internal/pull-notifications", json={"user_id": user_id})
resp = await client.post("/internal/pull-notifications", json={"user_id": user_id}) resp.raise_for_status()
resp.raise_for_status() data = PullResponse.model_validate(resp.json())
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: except (httpx.HTTPError, ValueError) as e:
logger.error(f"[FastAPI] Pull service failed for user_id={user_id}: {e!r}") logger.error(f"[FastAPI] Pull service failed for user_id={user_id}: {e!r}")
status = 504 if isinstance(e, httpx.TimeoutException) else 502 status = 504 if isinstance(e, httpx.TimeoutException) else 502
raise HTTPException(status_code=status, detail="Notification service unavailable") from e 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}") logger.info(f"[FastAPI] Returning {len(data.messages)} message(s) for user_id={user_id}, has_more={data.has_more}")
return PullResponse(messages=messages, count=len(messages), has_more=has_more) return data
async def start_servers(): async def start_servers():
logger.debug("Starting FastAPI and metrics servers") logger.debug("Starting FastAPI and metrics servers")