diff --git a/garven/calculate_dev_cluster.py b/garven/calculate_dev_cluster.py new file mode 100644 index 0000000..0ee8b03 --- /dev/null +++ b/garven/calculate_dev_cluster.py @@ -0,0 +1,24 @@ +import os + + +def get_dev_cluster() -> str: + guild_id = 601219766258106399 + shard_id = (guild_id >> 22) % int(os.environ["TOTAL_SHARDS"]) + number_of_shards_per_cluster = 5 + clusters = { + cid: [ + i + for i in range( + (cid - 1) * number_of_shards_per_cluster, + ((cid - 1) * number_of_shards_per_cluster) + + number_of_shards_per_cluster, + ) + ] + for cid in range(1, 20) + } + + for cluster, shards in clusters.items(): + if shard_id in shards: + return str(cluster) + + raise ValueError("Maths went wrong") diff --git a/garven/routers/cluster.py b/garven/routers/cluster.py index cc080d9..38ae82e 100644 --- a/garven/routers/cluster.py +++ b/garven/routers/cluster.py @@ -11,6 +11,7 @@ from starlette.status import HTTP_204_NO_CONTENT from zonis import RequestFailed, UnknownClient +from garven.calculate_dev_cluster import get_dev_cluster from garven.dependencies import get_auth_header from garven.schema import Message from garven.schema.cluster import ClusterHealth, DevShare @@ -53,7 +54,7 @@ async def notify_devs(request: Request, data: DevShare): z: Server = request.app.zonis await z.request( "share_with_devs", - client_identifier=os.environ.get("DEV_CLUSTER", "2"), + client_identifier=get_dev_cluster(), title=data.title, description=data.description, sender=data.sender,