From 39c8590bce399ff75407c1ba3515e8fb883119d6 Mon Sep 17 00:00:00 2001 From: spiral Date: Fri, 7 Jan 2022 14:25:08 -0500 Subject: [PATCH] refactor: move ExtractNodeIndex to BotConfig.Cluster class --- PluralKit.Bot/BotConfig.cs | 3 +++ PluralKit.Bot/Init.cs | 6 +----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/PluralKit.Bot/BotConfig.cs b/PluralKit.Bot/BotConfig.cs index db678ddf..7fc32232 100644 --- a/PluralKit.Bot/BotConfig.cs +++ b/PluralKit.Bot/BotConfig.cs @@ -32,5 +32,8 @@ public class BotConfig public string NodeName { get; set; } public int TotalShards { get; set; } public int TotalNodes { get; set; } + + // Node name eg. "pluralkit-3", want to extract the 3. blame k8s :p + public int NodeIndex => int.Parse(NodeName.Split("-").Last()); } } \ No newline at end of file diff --git a/PluralKit.Bot/Init.cs b/PluralKit.Bot/Init.cs index 8578d2d6..e48368ef 100644 --- a/PluralKit.Bot/Init.cs +++ b/PluralKit.Bot/Init.cs @@ -147,7 +147,7 @@ public class Init // For multi-instance deployments, calculate the "span" of shards this node is responsible for var totalNodes = config.Cluster.TotalNodes; var totalShards = config.Cluster.TotalShards; - var nodeIndex = ExtractNodeIndex(config.Cluster.NodeName); + var nodeIndex = config.Cluster.NodeIndex; // Should evenly distribute shards even with an uneven amount of nodes var shardMin = (int)Math.Round(totalShards * (float)nodeIndex / totalNodes); @@ -160,8 +160,4 @@ public class Init await cluster.Start(info); } } - - private static int ExtractNodeIndex(string nodeName) => - // Node name eg. "pluralkit-3", want to extract the 3. blame k8s :p - int.Parse(nodeName.Split("-").Last()); } \ No newline at end of file