diff options
| author | JP Dillingham <jp@dillingham.me> | 2026-02-17 22:10:12 -0600 |
|---|---|---|
| committer | JP Dillingham <jp@dillingham.me> | 2026-02-17 22:10:12 -0600 |
| commit | 9d9259214d9c3ce01758528ddcde508d7d895783 (patch) | |
| tree | 4db6c65f6c1b55f08b8775a64361fc350ad7273c /src | |
| parent | c5493131664457885f34172e15348db9fb2a95af (diff) | |
| download | slskd-9d9259214d9c3ce01758528ddcde508d7d895783.tar.gz | |
add base delay
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Common/Retry.cs | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/slskd/Common/Retry.cs b/src/slskd/Common/Retry.cs index f57b59d8..eff88659 100644 --- a/src/slskd/Common/Retry.cs +++ b/src/slskd/Common/Retry.cs @@ -34,6 +34,7 @@ namespace slskd /// <param name="isRetryable">A function returning a value indicating whether the last Exception is retryable.</param> /// <param name="onFailure">An action to execute on failure.</param> /// <param name="maxAttempts">The maximum number of retry attempts.</param> + /// <param name="baseDelayInMilliseconds">The base delay in milliseconds.</param> /// <param name="maxDelayInMilliseconds">The maximum delay in milliseconds.</param> /// <param name="cancellationToken">The token to monitor for cancellation requests.</param> /// <returns>The execution context.</returns> @@ -42,6 +43,7 @@ namespace slskd Func<int, Exception, bool> isRetryable = null, Action<int, Exception> onFailure = null, int maxAttempts = 3, + int baseDelayInMilliseconds = 1000, int maxDelayInMilliseconds = int.MaxValue, CancellationToken cancellationToken = default) { @@ -49,7 +51,7 @@ namespace slskd { await task(); return Task.FromResult<object>(null); - }, isRetryable, onFailure, maxAttempts, maxDelayInMilliseconds, cancellationToken); + }, isRetryable, onFailure, maxAttempts, baseDelayInMilliseconds, maxDelayInMilliseconds, cancellationToken); } /// <summary> @@ -59,6 +61,7 @@ namespace slskd /// <param name="isRetryable">A function returning a value indicating whether the last Exception is retryable.</param> /// <param name="onFailure">An action to execute on failure.</param> /// <param name="maxAttempts">The maximum number of retry attempts.</param> + /// <param name="baseDelayInMilliseconds">The base delay in milliseconds.</param> /// <param name="maxDelayInMilliseconds">The maximum delay in milliseconds.</param> /// <param name="cancellationToken">The token to monitor for cancellation requests.</param> /// <typeparam name="T">The Type of the logic return value.</typeparam> @@ -68,6 +71,7 @@ namespace slskd Func<int, Exception, bool> isRetryable = null, Action<int, Exception> onFailure = null, int maxAttempts = 3, + int baseDelayInMilliseconds = 1000, int maxDelayInMilliseconds = int.MaxValue, CancellationToken cancellationToken = default) { @@ -87,7 +91,7 @@ namespace slskd { if (attempts > 0) { - var (delay, jitter) = Compute.ExponentialBackoffDelay(attempts, maxDelayInMilliseconds); + var (delay, jitter) = Compute.ExponentialBackoffDelay(attempts, baseDelayInMilliseconds, maxDelayInMilliseconds); await Task.Delay(delay + jitter, cancellationToken); } |
