feat: add cluster ID to shard state

This commit is contained in:
spiral 2022-02-07 11:05:55 -05:00
parent f13c60a841
commit 1ec3663f63
No known key found for this signature in database
GPG Key ID: A6059F0CA0E1BD31
3 changed files with 9 additions and 1 deletions

View File

@ -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);
}

View File

@ -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);

View File

@ -11,6 +11,8 @@ message ShardState {
// unix timestamp
int32 last_heartbeat = 5;
int32 last_connection = 6;
optional int32 cluster_id = 7;
}
message GatewayEvent {