From bb672b1e22d0089abfa577298b3c7d19a1c0502d Mon Sep 17 00:00:00 2001 From: "Collin M. Barrett" Date: Sat, 1 Sep 2018 15:50:46 -0500 Subject: [PATCH] simplify snap fail logic --- src/FilterLists.Services/Snapshot/Snapshot.cs | 10 +++++----- src/FilterLists.Services/Snapshot/SnapshotService.cs | 2 +- src/FilterLists.Services/UserAgentService.cs | 2 -- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/FilterLists.Services/Snapshot/Snapshot.cs b/src/FilterLists.Services/Snapshot/Snapshot.cs index a03c166a6..80c441908 100644 --- a/src/FilterLists.Services/Snapshot/Snapshot.cs +++ b/src/FilterLists.Services/Snapshot/Snapshot.cs @@ -29,7 +29,6 @@ public class Snapshot private readonly string uaString; protected string ListUrl; private HashSet lines; - private bool wasWebException; public Snapshot() { @@ -46,7 +45,7 @@ public Snapshot(FilterListsDbContext dbContext, FilterListViewUrlDto list, strin telemetryClient = new TelemetryClient(); } - public bool RetryMirror => !SnapEntity.WasSuccessful && wasWebException; + public bool WebExcepted { get; private set; } public virtual async Task TrySaveAsync() => await TrySaveAsyncBase(); @@ -89,13 +88,13 @@ private async Task TryGetLines() } catch (HttpRequestException hre) { - wasWebException = true; + WebExcepted = true; await dbContext.SaveChangesAsync(); TrackException(hre); } catch (WebException we) { - wasWebException = true; + WebExcepted = true; SnapEntity.HttpStatusCode = (int)((HttpWebResponse)we.Response).StatusCode; await dbContext.SaveChangesAsync(); TrackException(we); @@ -141,7 +140,8 @@ private void SetChecksum(Stream stream) private async Task SaveIsNewChecksum() { - SnapEntity.WasUpdated = !SnapEntity.Md5Checksum.SequenceEqual(await GetPreviousChecksum() ?? Array.Empty()); + SnapEntity.WasUpdated = + !SnapEntity.Md5Checksum.SequenceEqual(await GetPreviousChecksum() ?? Array.Empty()); await dbContext.SaveChangesAsync(); return SnapEntity.WasUpdated; } diff --git a/src/FilterLists.Services/Snapshot/SnapshotService.cs b/src/FilterLists.Services/Snapshot/SnapshotService.cs index b1f599dcc..3ba75a1be 100644 --- a/src/FilterLists.Services/Snapshot/SnapshotService.cs +++ b/src/FilterLists.Services/Snapshot/SnapshotService.cs @@ -43,7 +43,7 @@ public async Task CaptureAsync(int batchSize) uaString = await UserAgentService.GetMostPopularString(); var lists = await GetListsToCapture(batchSize); var snaps = await CreateAndSaveSnaps(lists); - var listsToRetry = snaps.Where(s => s.RetryMirror).Select(s => s.List); + var listsToRetry = snaps.Where(s => s.WebExcepted).Select(s => s.List); await CreateAndSaveSnaps(listsToRetry); } diff --git a/src/FilterLists.Services/UserAgentService.cs b/src/FilterLists.Services/UserAgentService.cs index f50ad0f49..091e2e845 100644 --- a/src/FilterLists.Services/UserAgentService.cs +++ b/src/FilterLists.Services/UserAgentService.cs @@ -2,11 +2,9 @@ using System.IO; using System.Net.Http; using System.Threading.Tasks; -using JetBrains.Annotations; namespace FilterLists.Services { - [UsedImplicitly] public static class UserAgentService { private const string UaStringSource = "https://techblog.willshouse.com/2012/01/03/most-common-user-agents/";