mirror of
https://github.com/aljazceru/BTCPayServerPlugins.git
synced 2025-12-17 07:34:24 +01:00
attempt to remove coordinators when it's obviously down
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
<PropertyGroup>
|
||||
<Product>Coinjoin</Product>
|
||||
<Description>Allows you to integrate your btcpayserver store with coinjoins.</Description>
|
||||
<Version>1.0.104</Version>
|
||||
<Version>1.0.105</Version>
|
||||
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
@@ -338,8 +338,9 @@ public class WabisabiCoordinatorClientInstance:IHostedService
|
||||
});
|
||||
}
|
||||
|
||||
WasabiCoordinatorStatusFetcher = new WasabiCoordinatorStatusFetcher(sharedWabisabiClient, _logger);
|
||||
|
||||
WasabiCoordinatorStatusFetcher = new WasabiCoordinatorStatusFetcher(sharedWabisabiClient, _logger, () => serviceProvider.GetService<WabisabiCoordinatorClientInstanceManager>().RemoveCoordinator(this.CoordinatorName) );
|
||||
|
||||
|
||||
RoundStateUpdater =
|
||||
new RoundStateUpdater(TimeSpan.FromSeconds(5), sharedWabisabiClient, WasabiCoordinatorStatusFetcher);
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Immutable;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using WalletWasabi.Bases;
|
||||
using WalletWasabi.WabiSabi.Backend.PostRequests;
|
||||
@@ -14,15 +15,20 @@ public class WasabiCoordinatorStatusFetcher : PeriodicRunner, IWasabiBackendStat
|
||||
{
|
||||
private readonly IWabiSabiApiRequestHandler _wasabiClient;
|
||||
private readonly ILogger _logger;
|
||||
private readonly Action _onRemove;
|
||||
public bool Connected { get; set; } = false;
|
||||
public bool? OverrideConnected { get; set; }
|
||||
public WasabiCoordinatorStatusFetcher(IWabiSabiApiRequestHandler wasabiClient, ILogger logger) :
|
||||
|
||||
public WasabiCoordinatorStatusFetcher(IWabiSabiApiRequestHandler wasabiClient, ILogger logger, Action onRemove) :
|
||||
base(TimeSpan.FromSeconds(30))
|
||||
{
|
||||
_wasabiClient = wasabiClient;
|
||||
_logger = logger;
|
||||
_onRemove = onRemove;
|
||||
}
|
||||
|
||||
private int _retries = 0;
|
||||
|
||||
protected override async Task ActionAsync(CancellationToken cancel)
|
||||
{
|
||||
try
|
||||
@@ -33,20 +39,31 @@ public class WasabiCoordinatorStatusFetcher : PeriodicRunner, IWasabiBackendStat
|
||||
}
|
||||
else
|
||||
{
|
||||
await _wasabiClient.GetStatusAsync(new RoundStateRequest(ImmutableList<RoundStateCheckpoint>.Empty), cancel);
|
||||
var cts = CancellationTokenSource.CreateLinkedTokenSource(cancel);
|
||||
cts.CancelAfter(30000);
|
||||
await _wasabiClient.GetStatusAsync(new RoundStateRequest(ImmutableList<RoundStateCheckpoint>.Empty),
|
||||
cts.Token);
|
||||
if (!Connected)
|
||||
{
|
||||
_logger.LogInformation("Connected to coordinator" );
|
||||
_logger.LogInformation("Connected to coordinator");
|
||||
}
|
||||
Connected = true;
|
||||
}
|
||||
|
||||
|
||||
Connected = true;
|
||||
_retries = 0;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Connected = false;
|
||||
_retries++;
|
||||
if (_retries > 5)
|
||||
{
|
||||
_logger.LogError(e, "Could not connect to the coordinator after 5 retries, removing from the system");
|
||||
_onRemove.Invoke();
|
||||
}
|
||||
|
||||
await Task.Delay(Period * _retries, cancel);
|
||||
throw new Exception("Could not connect to the coordinator", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user