refactor: move ExtractNodeIndex to BotConfig.Cluster class
This commit is contained in:
parent
0d42328694
commit
39c8590bce
@ -32,5 +32,8 @@ public class BotConfig
|
|||||||
public string NodeName { get; set; }
|
public string NodeName { get; set; }
|
||||||
public int TotalShards { get; set; }
|
public int TotalShards { get; set; }
|
||||||
public int TotalNodes { 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());
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -147,7 +147,7 @@ public class Init
|
|||||||
// For multi-instance deployments, calculate the "span" of shards this node is responsible for
|
// For multi-instance deployments, calculate the "span" of shards this node is responsible for
|
||||||
var totalNodes = config.Cluster.TotalNodes;
|
var totalNodes = config.Cluster.TotalNodes;
|
||||||
var totalShards = config.Cluster.TotalShards;
|
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
|
// Should evenly distribute shards even with an uneven amount of nodes
|
||||||
var shardMin = (int)Math.Round(totalShards * (float)nodeIndex / totalNodes);
|
var shardMin = (int)Math.Round(totalShards * (float)nodeIndex / totalNodes);
|
||||||
@ -160,8 +160,4 @@ public class Init
|
|||||||
await cluster.Start(info);
|
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());
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user