From e194cd8054dd86ce4af520ebd5b7d7101bb2f15a Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Wed, 12 Mar 2025 09:32:10 +0100 Subject: [PATCH] =?UTF-8?q?feat:=20Implementierung=20der=20Wiederholungslo?= =?UTF-8?q?gik=20f=C3=BCr=20den=20Verbindungsaufbau=20in=20`AuthClient`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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. --- DigitalData.Auth.Client/AuthClient.cs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/DigitalData.Auth.Client/AuthClient.cs b/DigitalData.Auth.Client/AuthClient.cs index 2e69171..4601509 100644 --- a/DigitalData.Auth.Client/AuthClient.cs +++ b/DigitalData.Auth.Client/AuthClient.cs @@ -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 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);