-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathProgram.cs
More file actions
53 lines (51 loc) · 2.24 KB
/
Program.cs
File metadata and controls
53 lines (51 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using Mail2Gotify.Services;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Polly;
using Polly.Contrib.WaitAndRetry;
using Polly.Extensions.Http;
using System;
using System.IO;
using System.Net.Http;
using System.Reflection;
using System.Threading.Tasks;
namespace Mail2Gotify
{
class Program
{
static async Task Main(string[] args)
{
#pragma warning disable CA1416 // Validate platform compatibility
await Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration(builder => {
builder.SetBasePath(Directory.GetCurrentDirectory());
builder.AddJsonFile($"appsettings.json", optional: false);
builder.AddEnvironmentVariables();
})
.UseContentRoot(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location))
.ConfigureServices((hostContext, services) =>
{
services.AddHostedService<Mail2GotifyService>()
.AddSingleton<GotifyServiceAppProvider>()
.AddSingleton<GotifyService>()
.AddSingleton<GotifyMessageStore>()
.AddSingleton<GotifyUserAuthenticator>()
.AddSingleton<FileSystemCaching>()
.AddSingleton<CacheItemProcessingService>()
.AddHttpClient<StaticTokenCaller<GotifyServiceAppProvider>>()
.SetHandlerLifetime(TimeSpan.FromMinutes(5)) //Set lifetime to five minutes
.AddPolicyHandler(GetRetryPolicy()); ;
})
.RunConsoleAsync();
#pragma warning restore CA1416 // Validate platform compatibility
}
public static IAsyncPolicy<HttpResponseMessage> GetRetryPolicy()
{
return HttpPolicyExtensions
.HandleTransientHttpError()
.OrResult(msg => msg.StatusCode == System.Net.HttpStatusCode.NotFound)
.WaitAndRetryAsync(Backoff.DecorrelatedJitterBackoffV2(medianFirstRetryDelay: TimeSpan.FromSeconds(1), retryCount: 5));
}
}
}