From edbc02e8172b11345a60fb1e18c29c78dc1b6563 Mon Sep 17 00:00:00 2001 From: skelmis Date: Sun, 17 Dec 2023 16:29:04 +1300 Subject: [PATCH] feat: update to handle new clustering setup --- garven/routers/aggregate.py | 2 +- garven/routers/cluster.py | 4 +- garven/routers/premium.py | 78 ------------------------------------- 3 files changed, 3 insertions(+), 81 deletions(-) delete mode 100644 garven/routers/premium.py diff --git a/garven/routers/aggregate.py b/garven/routers/aggregate.py index 44997da..a9b07c2 100644 --- a/garven/routers/aggregate.py +++ b/garven/routers/aggregate.py @@ -37,7 +37,7 @@ async def guild_count(request: Request): statistic.statistic += item - cluster_count = int(os.environ.get("CLUSTER_COUNT", 6)) + cluster_count = int(os.environ.get("CLUSTER_COUNT", 11)) if len(data.keys()) != cluster_count: statistic.partial_response = True log.error( diff --git a/garven/routers/cluster.py b/garven/routers/cluster.py index 0db2cf6..cc080d9 100644 --- a/garven/routers/cluster.py +++ b/garven/routers/cluster.py @@ -39,7 +39,7 @@ async def cluster_status(request: Request): d.pop(k) continue - if len(d.values()) != int(os.environ.get("CLUSTER_COUNT", 6)): + if len(d.values()) != int(os.environ.get("CLUSTER_COUNT", 11)): partial_response = True return ClusterHealth(clusters=d, partial_response=partial_response) @@ -53,7 +53,7 @@ async def notify_devs(request: Request, data: DevShare): z: Server = request.app.zonis await z.request( "share_with_devs", - client_identifier="2", + client_identifier=os.environ.get("DEV_CLUSTER", "2"), title=data.title, description=data.description, sender=data.sender, diff --git a/garven/routers/premium.py b/garven/routers/premium.py deleted file mode 100644 index b796f5b..0000000 --- a/garven/routers/premium.py +++ /dev/null @@ -1,78 +0,0 @@ -from __future__ import annotations - -import logging -from typing import TYPE_CHECKING - -from fastapi import APIRouter, Depends, Query -from fastapi import Request -from starlette import status -from starlette.responses import Response, JSONResponse -from zonis import RequestFailed - -from garven.dependencies import get_auth_header -from garven.schema import Message -from garven.schema.premium import SharedGuildsRequest, SharedGuildsResponse - -if TYPE_CHECKING: - from zonis.server import Server - -log = logging.getLogger(__name__) - -premium_router = APIRouter( - prefix="/premium", - dependencies=[Depends(get_auth_header)], - tags=["Premium"], -) - - -@premium_router.post( - "/{user_id}/refresh", - description="Refresh premium data for the given user.", - status_code=204, - responses={503: {"model": Message}}, -) -async def refresh_premium(request: Request, user_id: int): - z: Server = request.app.zonis - data: dict = await z.request_all("refresh_premium", user_id=user_id) - for item in data.values(): - if isinstance(item, RequestFailed): - log.error("/{user_id}/refresh WS threw '%s'", item.response_data) - return JSONResponse( - status_code=status.HTTP_503_SERVICE_UNAVAILABLE, - content={"message": "Some bot clusters failed to refresh correctly."}, - ) - - return Response(status_code=status.HTTP_204_NO_CONTENT) - - -@premium_router.get( - "/{user_id}/guilds/shared", - description="Fetch guilds that the user shares with the bot.", - response_model=SharedGuildsResponse, - responses={400: {"model": Message}}, -) -async def fetch_shared_guilds( - request: Request, - user_id: int, - guild_ids: str = Query(description="Comma seperated list of guild ids."), -): - try: - guild_ids = guild_ids.split(",") - guild_ids = list(map(int, guild_ids)) - except: - return Response(Message(message="Invalid guild_ids param"), status_code=400) - - z: Server = request.app.zonis - d: dict[str, list[int]] = await z.request_all("shared_guilds", guild_ids=guild_ids) - data = SharedGuildsResponse(shared_guilds=[]) - for k, item in d.items(): - if isinstance(item, RequestFailed): - data.partial_response = True - log.error("/{user_id}/guilds/shared WS threw '%s'", item.response_data) - d.pop(k) - continue - - if item: - data.shared_guilds.extend(item) - - return data