Skip to content

Commit

Permalink
feat: add get_dev_cluster()
Browse files Browse the repository at this point in the history
  • Loading branch information
Skelmis committed Jan 4, 2024
1 parent 9a96cc9 commit 2a682a2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
24 changes: 24 additions & 0 deletions garven/calculate_dev_cluster.py
Original file line number Diff line number Diff line change
@@ -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")
3 changes: 2 additions & 1 deletion garven/routers/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 2a682a2

Please sign in to comment.