mirror of
https://github.com/collinbarrett/FilterLists.git
synced 2026-03-11 09:04:27 +00:00
parent
fd1a7cfb73
commit
7bcd1ba389
3 changed files with 40 additions and 4 deletions
|
|
@ -15,4 +15,5 @@
|
|||
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/WRAP_CHAINED_METHOD_CALLS/@EntryValue">CHOP_IF_LONG</s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateInstanceFields/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /></s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/PredefinedNamingRules/=PrivateStaticFields/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /></s:String>
|
||||
<s:Boolean x:Key="/Default/UserDictionary/Words/=appsettings/@EntryIndexedValue">True</s:Boolean>
|
||||
</wpf:ResourceDictionary>
|
||||
|
|
@ -16,16 +16,14 @@ public static class Program
|
|||
private static ServiceProvider serviceProvider;
|
||||
private static SnapshotService snapshotService;
|
||||
private static Logger logger;
|
||||
private static readonly TimeSpan OneHourTimeout = TimeSpan.FromHours(1);
|
||||
|
||||
public static async Task Main()
|
||||
{
|
||||
BuildConfigRoot();
|
||||
BuildServiceProvider();
|
||||
snapshotService = serviceProvider.GetService<SnapshotService>();
|
||||
using (logger = new Logger(configRoot[AppInsightsKeyConfig]))
|
||||
{
|
||||
await CaptureSnapshots(BatchSize);
|
||||
}
|
||||
await TryCaptureSnapshots();
|
||||
}
|
||||
|
||||
private static void BuildConfigRoot() =>
|
||||
|
|
@ -41,6 +39,21 @@ private static void BuildServiceProvider()
|
|||
serviceProvider = serviceCollection.BuildServiceProvider();
|
||||
}
|
||||
|
||||
private static async Task TryCaptureSnapshots()
|
||||
{
|
||||
using (logger = new Logger(configRoot[AppInsightsKeyConfig]))
|
||||
{
|
||||
try
|
||||
{
|
||||
await CaptureSnapshots(BatchSize).TimeoutAfter(OneHourTimeout);
|
||||
}
|
||||
catch (TimeoutException)
|
||||
{
|
||||
logger.Log("Timeout - Program.CaptureSnapshots()");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static async Task CaptureSnapshots(int batchSize)
|
||||
{
|
||||
logger.Log("Capturing FilterList snapshots...");
|
||||
|
|
|
|||
22
src/FilterLists.Agent/TaskExtensions.cs
Normal file
22
src/FilterLists.Agent/TaskExtensions.cs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FilterLists.Agent
|
||||
{
|
||||
public static class TaskExtensions
|
||||
{
|
||||
//https://stackoverflow.com/a/22078975/2343739
|
||||
public static async Task TimeoutAfter(this Task task, TimeSpan timeout)
|
||||
{
|
||||
using (var cancellationTokenSource = new CancellationTokenSource())
|
||||
{
|
||||
var completedTask = await Task.WhenAny(task, Task.Delay(timeout, cancellationTokenSource.Token));
|
||||
if (completedTask != task)
|
||||
throw new TimeoutException("The operation has timed out.");
|
||||
cancellationTokenSource.Cancel();
|
||||
await task;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue