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:
Developer 02 2025-03-12 09:32:10 +01:00
parent d21e0c06e7
commit e194cd8054

View File

@ -39,11 +39,32 @@ public class AuthClient : IAuthClient, IHostedService
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;
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)
{
await _connection.StopAsync(cancellationToken);