mirror of
https://github.com/RedWizardsLab/EchoHub.git
synced 2026-09-04 08:36:11 +02:00
feat: Add heartbeat handling to ServerDirectoryService for connection health checks
This commit is contained in:
@@ -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
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user