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