Skip to content

Commit 8d6fbc5

Browse files
committed
Replace magic number with constant for max retry attempts in TrackedDownload
1 parent 9ba4d32 commit 8d6fbc5

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

StabilityMatrix.Core/Models/TrackedDownload.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public class TrackedDownload
7878
[JsonIgnore]
7979
public Exception? Exception { get; private set; }
8080

81+
private const int MaxRetryAttempts = 3;
8182
private int attempts;
8283
private CancellationTokenSource? retryDelayCancellationTokenSource;
8384

@@ -381,7 +382,7 @@ private void OnDownloadTaskCompleted(Task task)
381382
// Set the exception
382383
Exception = task.Exception;
383384

384-
if (IsTransientNetworkException(Exception) && attempts < 3)
385+
if (IsTransientNetworkException(Exception) && attempts < MaxRetryAttempts)
385386
{
386387
attempts++;
387388
Logger.Warn(
@@ -397,10 +398,11 @@ private void OnDownloadTaskCompleted(Task task)
397398
var delayMs =
398399
(int)Math.Min(2000 * Math.Pow(2, attempts - 1), 30_000) + Random.Shared.Next(-500, 500);
399400
Logger.Debug(
400-
"Download {Download} retrying in {Delay}ms (attempt {Attempt}/3)",
401+
"Download {Download} retrying in {Delay}ms (attempt {Attempt}/{MaxAttempts})",
401402
FileName,
402403
delayMs,
403-
attempts
404+
attempts,
405+
MaxRetryAttempts
404406
);
405407

406408
// Persist Inactive to disk before the delay so a restart during backoff loads it as resumable.

0 commit comments

Comments
 (0)