mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
add AI exception tracking to SnapshotService
This commit is contained in:
parent
d566db9e59
commit
9b232ff278
1 changed files with 16 additions and 4 deletions
|
|
@ -4,11 +4,13 @@
|
|||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using FilterLists.Data;
|
||||
using FilterLists.Data.Entities.Junctions;
|
||||
using FilterLists.Services.Extensions;
|
||||
using FilterLists.Services.Snapshot.Models;
|
||||
using Microsoft.ApplicationInsights;
|
||||
using MoreLinq;
|
||||
|
||||
namespace FilterLists.Services.Snapshot
|
||||
|
|
@ -19,11 +21,13 @@ public class Snapshot
|
|||
private readonly FilterListsDbContext dbContext;
|
||||
private readonly FilterListViewUrlDto list;
|
||||
private readonly Data.Entities.Snapshot snapEntity;
|
||||
private readonly TelemetryClient telemetryClient;
|
||||
|
||||
public Snapshot(FilterListsDbContext dbContext, FilterListViewUrlDto list)
|
||||
{
|
||||
this.dbContext = dbContext;
|
||||
this.list = list;
|
||||
telemetryClient = new TelemetryClient();
|
||||
snapEntity = new Data.Entities.Snapshot
|
||||
{
|
||||
FilterListId = list.Id,
|
||||
|
|
@ -39,10 +43,9 @@ public async Task TrySaveAsync()
|
|||
{
|
||||
await SaveAsync();
|
||||
}
|
||||
catch (Exception)
|
||||
catch (Exception e)
|
||||
{
|
||||
//allow other snapshots to continue
|
||||
//TODO: log
|
||||
TrackException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -74,13 +77,15 @@ private async Task<IEnumerable<string>> TryGetLines()
|
|||
{
|
||||
return await GetLines();
|
||||
}
|
||||
catch (HttpRequestException)
|
||||
catch (HttpRequestException hre)
|
||||
{
|
||||
TrackException(hre);
|
||||
return null;
|
||||
}
|
||||
catch (WebException we)
|
||||
{
|
||||
snapEntity.HttpStatusCode = ((int)((HttpWebResponse)we.Response).StatusCode).ToString();
|
||||
TrackException(we);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -155,5 +160,12 @@ private async Task SetSuccessful()
|
|||
snapEntity.WasSuccessful = true;
|
||||
await dbContext.SaveChangesAsync();
|
||||
}
|
||||
|
||||
private void TrackException(Exception e)
|
||||
{
|
||||
telemetryClient.TrackException(e);
|
||||
telemetryClient.Flush();
|
||||
Thread.Sleep(5000);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue