feat: Add heartbeat handling to ServerDirectoryService for connection health checks

This commit is contained in:
HueByte
2026-02-19 15:17:19 +01:00
parent 159a28e890
commit 257ac34224
@@ -61,6 +61,19 @@ public sealed class ServerDirectoryService : BackgroundService
{ {
var connectionPermanentlyClosed = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously); var connectionPermanentlyClosed = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
connection.On("Ping", async () =>
{
_logger.LogDebug("Received alive check from directory — sending heartbeat");
try
{
await connection.InvokeAsync("Heartbeat");
}
catch (Exception ex)
{
_logger.LogWarning(ex, "Failed to send heartbeat response");
}
});
connection.Reconnected += async _ => connection.Reconnected += async _ =>
{ {
_logger.LogInformation("Reconnected to directory — re-registering server"); _logger.LogInformation("Reconnected to directory — re-registering server");
@@ -156,8 +169,6 @@ public sealed class ServerDirectoryService : BackgroundService
continue; continue;
var currentCount = _presenceTracker.GetOnlineUserCount(); var currentCount = _presenceTracker.GetOnlineUserCount();
if (currentCount == _lastReportedUserCount)
continue;
try try
{ {