attempt to gracefully reconnect, do not send notification for player on connect, do not check other players on framework update thread, delay palette+ sending data

This commit is contained in:
rootdarkarchon
2023-02-04 02:04:26 +01:00
parent 680c5f4712
commit fc3ad1f7f8
6 changed files with 58 additions and 24 deletions

View File

@@ -1,11 +1,35 @@
using Microsoft.AspNetCore.SignalR.Client;
using MareSynchronos.Mediator;
using Microsoft.AspNetCore.SignalR.Client;
namespace MareSynchronos.WebAPI.Utils;
public class ForeverRetryPolicy : IRetryPolicy
{
private readonly MareMediator _mediator;
private bool _sentDisconnected = false;
public ForeverRetryPolicy(MareMediator mediator)
{
_mediator = mediator;
}
public TimeSpan? NextRetryDelay(RetryContext retryContext)
{
return TimeSpan.FromSeconds(new Random().Next(10, 20));
TimeSpan timeToWait = TimeSpan.FromSeconds(new Random().Next(10, 20));
if (retryContext.PreviousRetryCount == 0)
{
_sentDisconnected = false;
timeToWait = TimeSpan.FromSeconds(1);
}
else if (retryContext.PreviousRetryCount == 1) timeToWait = TimeSpan.FromSeconds(2);
else if (retryContext.PreviousRetryCount == 2) timeToWait = TimeSpan.FromSeconds(3);
else
{
if (!_sentDisconnected)
_mediator.Publish(new DisconnectedMessage());
_sentDisconnected = true;
}
return timeToWait;
}
}