-
Notifications
You must be signed in to change notification settings - Fork 558
/
Program.cs
66 lines (53 loc) · 1.84 KB
/
Program.cs
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
54
55
56
57
58
59
60
61
62
63
64
65
66
using ClassifiedAds.Infrastructure.HealthChecks;
using ClassifiedAds.Infrastructure.Logging;
using DbUp;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Polly;
using System;
using System.Reflection;
namespace ClassifiedAds.Migrator;
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
var services = builder.Services;
var configuration = builder.Configuration;
builder.WebHost.UseClassifiedAdsLogger(configuration =>
{
return new LoggingOptions();
});
if (string.Equals(configuration["CheckDependency:Enabled"], "true", StringComparison.OrdinalIgnoreCase))
{
NetworkPortCheck.Wait(configuration["CheckDependency:Host"], 5);
}
services.AddDateTimeProvider();
services.AddPersistence(configuration["ConnectionStrings:ClassifiedAds"], Assembly.GetExecutingAssembly().GetName().Name);
// Configure the HTTP request pipeline.
var app = builder.Build();
Policy.Handle<Exception>().WaitAndRetry(new[]
{
TimeSpan.FromSeconds(10),
TimeSpan.FromSeconds(20),
TimeSpan.FromSeconds(30),
})
.Execute(() =>
{
app.MigrateAdsDb();
var upgrader = DeployChanges.To
.SqlDatabase(configuration.GetConnectionString("ClassifiedAds"))
.WithScriptsEmbeddedInAssembly(Assembly.GetExecutingAssembly())
.LogToConsole()
.Build();
var result = upgrader.PerformUpgrade();
if (!result.Successful)
{
throw result.Error;
}
});
app.Run();
}
}