feat: Implementierung der Wiederholungslogik für den Verbindungsaufbau in AuthClient
- Hinzugefügt: `TryStartConnectionAsync`-Methode zur Durchführung von Verbindungsversuchen mit Wiederholungslogik. - `StartAsync` aktualisiert, um wiederholt zu versuchen, die Verbindung herzustellen, bis sie erfolgreich ist oder `RetryDelay` erschöpft ist.
This commit is contained in:
parent
d21e0c06e7
commit
e194cd8054
@ -39,11 +39,32 @@ public class AuthClient : IAuthClient, IHostedService
|
|||||||
|
|
||||||
public async Task StartAsync(CancellationToken cancellationToken = default)
|
public async Task StartAsync(CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
await _connection.StartAsync(cancellationToken);
|
while(!await TryStartConnectionAsync(cancellationToken))
|
||||||
|
{
|
||||||
|
if (_params.RetryDelay is not null)
|
||||||
|
await Task.Delay(_params.RetryDelay.Value.Milliseconds, cancellationToken);
|
||||||
|
else
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
IsConnected = true;
|
IsConnected = true;
|
||||||
await GetAllPublicKeysAsync();
|
await GetAllPublicKeysAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task<bool> TryStartConnectionAsync(CancellationToken cancellationToken = default)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await _connection.StartAsync(cancellationToken);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch(HttpRequestException ex)
|
||||||
|
{
|
||||||
|
_logger?.LogError(ex, "Connection is failed. {message}", ex.Message);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async Task StopAsync(CancellationToken cancellationToken)
|
public async Task StopAsync(CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
await _connection.StopAsync(cancellationToken);
|
await _connection.StopAsync(cancellationToken);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user