From 94cc20bf6293a2c1114a28cf0c28deec6e4ba24b Mon Sep 17 00:00:00 2001 From: "Collin M. Barrett" Date: Fri, 24 Aug 2018 18:28:35 -0500 Subject: [PATCH] cleanup failed snapshots --- src/FilterLists.Services/Snapshot/SnapshotService.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/FilterLists.Services/Snapshot/SnapshotService.cs b/src/FilterLists.Services/Snapshot/SnapshotService.cs index 7dae4d93b..53d51757f 100644 --- a/src/FilterLists.Services/Snapshot/SnapshotService.cs +++ b/src/FilterLists.Services/Snapshot/SnapshotService.cs @@ -23,6 +23,7 @@ public SnapshotService(FilterListsDbContext dbContext, IConfigurationProvider ma public async Task CaptureAsync(int batchSize) { + await CleanupFailedSnapshots(); uaString = await UserAgentService.GetMostPopularString(); var lists = await GetListsToCapture(batchSize); var snaps = await CreateAndSaveSnaps(lists); @@ -30,6 +31,12 @@ public async Task CaptureAsync(int batchSize) await CreateAndSaveSnaps(listsToRetry); } + private async Task CleanupFailedSnapshots() + { + DbContext.SnapshotRules.RemoveRange(DbContext.SnapshotRules.Where(sr => !sr.Snapshot.WasSuccessful)); + await DbContext.SaveChangesAsync(); + } + private async Task> GetListsToCapture(int batchSize) => await DbContext .FilterLists