feat: add cluster ID to shard state
This commit is contained in:
parent
f13c60a841
commit
1ec3663f63
@ -61,6 +61,8 @@ public static class PrivateJsonExt
|
||||
s.Add("disconnection_count", shard.DisconnectionCount);
|
||||
s.Add("last_heartbeat", shard.LastHeartbeat.ToString());
|
||||
s.Add("last_connection", shard.LastConnection.ToString());
|
||||
if (shard.HasClusterId)
|
||||
s.Add("cluster_id", shard.ClusterId);
|
||||
|
||||
o.Add(s);
|
||||
}
|
||||
|
@ -16,16 +16,18 @@ namespace PluralKit.Bot;
|
||||
|
||||
public class ShardInfoService
|
||||
{
|
||||
private readonly int? _clusterId;
|
||||
private readonly ILogger _logger;
|
||||
private readonly Cluster _client;
|
||||
private readonly RedisService _redis;
|
||||
private readonly Dictionary<int, ShardInfo> _shardInfo = new();
|
||||
|
||||
public ShardInfoService(ILogger logger, Cluster client, RedisService redis)
|
||||
public ShardInfoService(ILogger logger, Cluster client, RedisService redis, BotConfig config)
|
||||
{
|
||||
_logger = logger.ForContext<ShardInfoService>();
|
||||
_client = client;
|
||||
_redis = redis;
|
||||
_clusterId = config.Cluster?.NodeIndex;
|
||||
}
|
||||
|
||||
public void Init()
|
||||
@ -65,6 +67,8 @@ public class ShardInfoService
|
||||
|
||||
// latency = 0 because otherwise shard 0 would serialize to an empty array, thanks protobuf
|
||||
var state = new ShardState() { ShardId = shard.ShardId, Up = false, Latency = 1 };
|
||||
if (_clusterId != null)
|
||||
state.ClusterId = _clusterId.Value;
|
||||
|
||||
// Register listeners for new shard
|
||||
shard.Resumed += () => ReadyOrResumed(shard);
|
||||
|
@ -11,6 +11,8 @@ message ShardState {
|
||||
// unix timestamp
|
||||
int32 last_heartbeat = 5;
|
||||
int32 last_connection = 6;
|
||||
|
||||
optional int32 cluster_id = 7;
|
||||
}
|
||||
|
||||
message GatewayEvent {
|
||||
|
Loading…
Reference in New Issue
Block a user